Is there any difference between exit()
and raise ValueError("example")
except for the fact that I will have an error print on my output when using raise ValueError("example")
?
There is a huge difference.
sys.exit()
raises a SystemExit
exception, which Python always catches and turns into a program exit code.
Raising ValueError
, if uncaught, triggers the sys.excepthook()
handler, after which Python exits. The default except hook prints the traceback of the exception to stderr
, after which Python exits with an exit code of 1.
The sys.excepthook()
function is never called for SystemExit
, so you cannot customize the handling of that exception, but you can handle the handling of ValueError
and other exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With