Class Reference
Please see the Quick Start guide for some examples to get started using the ExceptionControl package.
Class Guide
- class exceptioncontrol.ExceptionControl.ExceptionControl[source]
Bases:
objectThe
ExceptionControlclass is intended as a helper class that would be inherited as a superclass to some other class to give it the capability to implement conditional exception handling options.This allows developers to create conditional exceptions in their class which can do nothing, print a warning, or raise an exception based on the severity of the issue and the threshold level setting, which is set via a property.
There are six ‘types’ of events that can be created:
WARNING: The lowest severity. These are mostly informative, they might not indicate an error but we might want them to make note of something that isn’t quite right.
SILENT: Shares the same severity level as “WARNING” but these events will never print a warning out. They will trigger the exception if the
exception_control_levelis set to 5, which is the same level that will trigger WARNING events to raise their exceptions. These are useful if you wish to keep output relatively clean but still want the event to be there.MINOR: This is more severe than a WARNING type and indicates that an actual error probably happened but not a major one. This might be somethig that needs to be noted but doesn’t always warrant halting execution.
SERIOUS: Second highest level of severity. This indicates something serious happened. We would definitely want to handle this and call out that a problem happened. The likelihood that this kind of event should halt execution and/or throw an exception rather than print out a message is high.
CRITICAL: The highest severity of event that might not be raised depending on the value of
exception_control_level. This would generally indicate something went seriously wrong and we should definitely raise the exception and halt execution.CATASTROPHIC: This kind of event is the highest level of severity and will always raise the associated exception. These cannot be opted out of.
When events are raised, we will set them to the appropriate type and the behaviour can be determined based on the
exception_control_levelproperty on the class. This property determines how an event is handled. The values allowed for this are 0 through 5, where:No Exceptions!: Events do not print out anything nor do they raise an exception.
Warnings Only: A warning message is printed out for all events. No exceptions get raised.
Raise critical events: CRITICAL events will cause the exception to be raised. Lower severity events will print out a warning message.
Raise serious or critical events: CRITICAL and SERIOUS events will raise the associated exception. Lower severity events will print out a warning message.
Raise minor, serious and critical events: CRITICAL, SERIOUS and MINOR events will raise their associated exception. Lower severity events will print out a warning message. This is the DEFAULT value.
Always Raise: All events trigger their associated exception, even WARNING and SILENT events.
The default behavior is to set
exception_control_levelto 4 which will raise CRITICAL, SERIOUS, and MINOR events’ associated exceptions and will issue a warning for MINOR and WARNING events. Note that CATASTROPHIC events can not be suppressed. Also that any event that issues only a warning can be shortened via theexception_control_compact_warningsflag or silenced by setting theexception_control_silent_warningsflag.- property exception_control_compact_warnings: bool
A flag that toggles compact warnings.
This
booleanproperty toggles the use of compact warnings.- Returns:
Truewill set warnings to be compact in natureand print out just a short warning rather than the full warning.
- Return type:
bool
- exception_control_event(event_type, exception_type, message=None)[source]
An event that conditinally raises an exception.
Triggers an event that will be handled based on the rules given by the current
exception_control_levelvalue and the severity class of this event.- Parameters:
event_type (str) – Sets the type of exception this is. Valid entries are [“SILENT”,” WARNING”, “MINOR”, “SERIOUS”, “CRITICAL”, “CATASTROPHIC”].
exception_type (object) – An
Exceptiontype that would be raised if theexception_control_levelthreshold is high enough to make this exception get raised. This must be anException(or a derivitive) type.message (str) – If the exception gets triggered, what message should we pass along when it gets raised?
- property exception_control_level
Get the value of the
exception_control_levelproperty.The parameter must be convertable to an integer and must be between 0 and 5. Values below 0 will be set to 0 and values greater than 5 will be set to 5.
The default value is set to 4 (CRITICAL, SERIOUS, and MINOR events will raise an exception; WARNING events will only warn).
- Returns:
The
exception_control_levelvalue.- Return type:
int
- property exception_control_silent_warnings: bool
A flag that toggles silencing of warnings.
This
booleanproperty toggles whether or notexception_control_eventshould silence events that don’t raise their associated exception.- Returns:
Trueto cause events that don’t raise their exceptionto suppress their associated exception message.
Falseif we do not wish to suppress warning messages.
- Return type:
bool