Skip to content

[Bug] Dead exception handlers in DataFileClass.run() due to incorrect exception order #400

@mohityadav8

Description

@mohityadav8

Summary

In DataFileClass.run() (DataFileClass.py ~line 2265), the exception handlers are ordered incorrectly.

The block except Exception as ex: appears before the more specific exception handlers except (IOError, IndexError) and except OSError.

Since Exception is the superclass of these exceptions, it catches them first. As a result, the later handlers are unreachable and effectively dead code.

Expected behavior

Specific exceptions should be handled before the generic Exception handler so that they are reachable.

Correct order example:

try:

except (IOError, IndexError):
    raise IndexError
except OSError:
    raise OSError
except Exception as ex:
    print(ex)
    raise
     

Reproduction steps

  1. Open the repository.
  2. Navigate to DataFileClass.py.
  3. Locate the run() method around line ~2265.
  4. Observe the exception handling block where except Exception as ex appears before specific exceptions.
  5. Because Exception is a superclass, the later handlers for (IOError, IndexError) and OSError will never execute.

Environment

OS: Windows 11
Python version: Python 3.13.9
Shell: Windows PowerShell
Environment: Conda base environment
Branch: main (or latest development branch)

Logs or screenshots

No response

Related work checked

Searched existing issues for "exception order", "dead exception handler", and "unreachable except block" but did not find an existing report.

Proposed track

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions