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


Groups > comp.lang.python > #15786 > unrolled thread

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

Started byChristian Heimes <lists@cheimes.de>
First post2011-11-16 19:47 +0100
Last post2011-11-16 19:47 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: try - except. How to identify errors unknown in advance? Christian Heimes <lists@cheimes.de> - 2011-11-16 19:47 +0100

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

FromChristian Heimes <lists@cheimes.de>
Date2011-11-16 19:47 +0100
SubjectRe: try - except. How to identify errors unknown in advance?
Message-ID<mailman.2780.1321469278.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web