Skip to content

Fix unreachable exception handlers by reordering specific exceptions before generic Exception#401

Open
mohityadav8 wants to merge 2 commits intoEAPD-DRB:mainfrom
mohityadav8:fix-exception-handler-order
Open

Fix unreachable exception handlers by reordering specific exceptions before generic Exception#401
mohityadav8 wants to merge 2 commits intoEAPD-DRB:mainfrom
mohityadav8:fix-exception-handler-order

Conversation

@mohityadav8
Copy link
Copy Markdown

…before generic Exception

Linked issue

Existing related work reviewed

  • Issues/PRs reviewed: searched for "exception order", "dead exception handler", and "unreachable except block"
  • None found after search

Overlap assessment

  • Classification: Bug fix
  • Overlapping items: None identified
  • Why this is not duplicate/superseded:
    The current implementation places except Exception before more specific exception handlers, making the latter unreachable.

Why this PR should proceed

  • Fixes unreachable exception handlers
  • Improves correctness of exception handling
  • Ensures specific exceptions are caught before the generic fallback

Summary

  • What changed:
    Reordered exception blocks so that specific exceptions (IOError, IndexError, OSError) appear before the generic Exception handler.

  • Why:
    In Python, exception handlers are evaluated from top to bottom.
    If Exception appears first, it catches all exceptions and prevents later specific handlers from executing.

Validation

  • Tests added/updated (or not applicable)
  • Validation steps documented
  • Evidence attached (logs/screenshots/output as relevant)

Validation steps:

  1. Located exception blocks where except Exception appeared before specific exceptions.
  2. Reordered them so specific exceptions are handled first.
  3. Confirmed code executes correctly and no unreachable exception handlers remain.

Documentation

  • Docs updated in this PR (or not applicable)
  • Any setup/workflow changes reflected in repo docs

Scope check

  • No unrelated refactors
  • Implemented from a feature branch
  • Change is deliverable without upstream OSeMOSYS/MUIO dependency
  • Base repo/branch is EAPD-DRB/MUIOGO:main (not upstream)

Exception rationale

N/A

@mohityadav8 mohityadav8 marked this pull request as ready for review April 1, 2026 20:04
@mohityadav8
Copy link
Copy Markdown
Author

@autibet @SeaCelo please review this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant