Last active
February 23, 2026 15:36
-
-
Save roganjoshp/0ae629559cf3d438c10422a1aafc6963 to your computer and use it in GitHub Desktop.
Custom exceptions in a library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # exceptions.py | |
| class ProblemError(Exception): | |
| """An exception raised during problem specification""" | |
| class ShiftError(ProblemError): | |
| """Some aspect of the shift pattern definition is invalid""" | |
| # shifts.py (collected exceptions from the module) | |
| raise ShiftError("No hours are registered for this shift") | |
| raise ShiftError("The shift day does not start at midnight") | |
| raise ShiftError( | |
| ( | |
| "Non-contiguous shift block encountered between: " | |
| f"{self.periods[i]} and {self.periods[i + 1]}" | |
| ).lstrip() | |
| ) | |
| raise ShiftError( | |
| ( | |
| "The following shift does not run until midnight: " | |
| f"{self.periods[-1]['end']}" | |
| ).lstrip() | |
| ) | |
| raise ShiftError( | |
| ( | |
| "The date of the first shift activity of this pattern " | |
| "does not match the reference start date. If no shift " | |
| "activity is planned for this day, use `add_downday()`" | |
| " to fill in any gaps." | |
| ).lstrip() | |
| ) | |
| raise ShiftError("Shift pattern is not contiguous in days") | |
| raise ShiftError("Shift pattern has not been built") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment