Skip to content

Bug: Tic-Tac-Toe bare except silently swallows non-font errors during font initialization #1305

Description

@vipul674

Description

In games/Tic-Tac-Toe/Tic-Tac-Toe.py lines 38 and 45, bare except: pass blocks catch ALL exceptions during font creation, not just font-related errors. This means any unexpected error (e.g., a typo in the font path, permission error, or a bug in the rendering logic) is silently swallowed.

Code

try:
    font = pygame.font.SysFont('arial', 50, bold=True)
except:
    pass

try:
    font = pygame.font.SysFont('helvetica', 50, bold=True)
except:
    pass

Impact

If a non-font error occurs during these try blocks (e.g., a NameError if pygame isn't properly imported, or a permission error), the game silently continues with no font set, leading to confusing behavior later. Developers cannot diagnose issues because errors are completely hidden.

Expected Behavior

Catch only the specific font-related exception (pygame.error) so other errors propagate:

try:
    font = pygame.font.SysFont('arial', 50, bold=True)
except pygame.error:
    pass

Labels

bug, GSSoC

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions