try:
#What kind of chords?
except IOError:
#Exception Processing
It's not about every one of the exceptions, but just catch all the exceptions at once
I'd like to take care of it. Is it possible?
exception-handling python
You can squeeze it like this if you want. (The code below also handles keyboard interrupts such as sigint)
try:
do_something()
except:
print "I got you!"
Codes that handle all exceptions at once are not recommended by Python. (It's okay if you raise it again in the exception as below.))
try:
do_something()
except:
raise
I don't know why you want to catch exceptions at once, but if you do it for logging,
import traceback
import logging
try:
do_something()
except Exception as e:
logging.error(traceback.format_exc()) #Logging
You can share it.
© 2024 OneMinuteCode. All rights reserved.