How can I catch all exception in python?
Collapse
This topic is closed.
X
X
-
yinglcs@gmail.comTags: None -
kyosohma@gmail.com
Re: How can I catch all exception in python?
On Mar 27, 1:09 pm, "ying...@gmail. com" <ying...@gmail. comwrote:Technically speaking, you can catch all errors as follows:I read the document here about exception handling in python:
>
Learn how to open, read, write, and perform file operations in Python with built-in functions and libraries. A list of modes for a file handling.
>
Can you please tell me how can I catch all exception in python?
like this in Java:
try {
....
>
} catch (Throwable t) {
...
}
try:
# do something
except Exception, e:
print e
However, this is NOT the recommended way of handling errors. Typically
you catch only expected errors, such as when you open a file, you
check for an IOError. By catching all errors, you will learn less and
likely have hard-to-understand bugs in your program.
Mike
-
Gabriel Genellina
Re: How can I catch all exception in python?
En Tue, 27 Mar 2007 15:09:18 -0300, yinglcs@gmail.c om <yinglcs@gmail. com>
escribió:
See the Further Reading section on that same page.I read the document here about exception handling in python:
>
Learn how to open, read, write, and perform file operations in Python with built-in functions and libraries. A list of modes for a file handling.
>
Can you please tell me how can I catch all exception in python?
like this in Java:
try {
....
} catch (Throwable t) {
...
}
Exceptions are covered in the Python Tutorial here:
--
Gabriel Genellina
Comment
-
irstas@gmail.com
Re: How can I catch all exception in python?
On Mar 27, 9:15 pm, kyoso...@gmail. com wrote:That won't catch exceptions/errors that don't derive fromTechnically speaking, you can catch all errors as follows:
>
try:
# do something
except Exception, e:
print e
Exception class. For example a string won't be caught:
try:
raise "foo"
except Exception, e:
print e
But this will catch all exceptions:
try:
raise "foo"
except:
print sys.exc_info()
(there may be other ways I don't know of)
Comment
Comment