Is it possible to register custom error handler in python – like http://php.net/set_error_handler in PHP?
I would like to trigger errors from anywhere in my code and then have email notifications about that (and logging, and anything else I need I’d implement in handler) – I used such pattern in PHP.
maybe I don’t understand python’s concept well (since I’m newbie in python). Thanks for help.
Not knowing exactly what error handlers are in PHP I will look at this from a python point of view
In python we have exceptions, they are by name exceptional. We throw exceptions when something goes wrong or we are expecting something else or even we just want to fail. Exceptions can be thrown at any point, and then later caught for example
Will throw an exception because you cannot convert ‘int’ to an int, so now to do this with exception handling
Now you notice we swallow the exception and carry on execution of the program, this isn’t always the best idea, sometimes we might want to raise our own exception and crash
Now we get our custom exception with a custom message