Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15786

Re: try - except. How to identify errors unknown in advance?

From Christian Heimes <lists@cheimes.de>
Subject Re: try - except. How to identify errors unknown in advance?
Date 2011-11-16 19:47 +0100
References <1321462647.2315.31.camel@hatchbox-one> <CALvWhxtY+gaC+xHx4qdakAMstFkOC8eUxRiV9tBGRO3Q46QqXw@mail.gmail.com> <1321468772.2315.35.camel@hatchbox-one>
Newsgroups comp.lang.python
Message-ID <mailman.2780.1321469278.27778.python-list@python.org> (permalink)

Show all headers | View raw


Am 16.11.2011 19:39, schrieb Frederic Rentsch:
>> py>import sys
>> py>try:
>> py> raise RuntimeError
>> py> except:
>> py> print sys.exc_info()
>> py>
>> (<type 'exceptions.RuntimeError'>, RuntimeError(), <traceback object
>> at 0x0000000002371588>)
> 
> Chris, Thanks very much! Great help!

How about using the excellent logging framework instead of rolling your
own stuff? It can print the traceback, too.

>>> import logging
>>> logging.basicConfig()
>>> log = logging.getLogger("mymodule")
>>> try:
...     raise ValueError("test")
... except Exception:
...     log.exception("some message")
...
ERROR:mymodule:some message
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ValueError: test

Christian

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

#15786 

csiph-web