Print Error Type when I catch it
Chris Rebert
clp2 at rebertia.com
Thu Apr 22 20:07:51 EDT 2010
On Thu, Apr 22, 2010 at 4:50 PM, Jimbo <nilly16 at yahoo.com> wrote:
> I have a relatively simple question. I want to use a try except in a
> function & when an error occurs I want to print the error type name(eg
> IOError, OSError etc) do you know how I can do this without specifying
> all possible errors, eg having to do this "except (IOError, OSError,
> IndexError, ....):"
>
> try:
>
> ... some code
>
> except:
> # Here I want to print type of error that occured
> print errorType
>
> The reason I want to do this is because one of my complex programs is
> crashing BUT no python error message is comming up in red when I run
> it, so I cant figure out what error occured? So I think its time I
> learnt to print out my own errors & their types
try:
# code
except Exception as exc:
print type(exc).__name__
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list