Raising vs Reraising exceptions in python

>>> def foo(x):
...    raise Exception('%s is invalid input' % x)
...
>>> try:
...     foo(1)
... except Exception, e:
...     raise e                          # RE-RAISING EXCEPTIONS
...
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>    # LOSES foo
Exception: 1 is invalid input
>>> try:
...     foo(1)
... except Exception:
...     raise                             # RAISING EXCEPTIONS
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 2, in foo          # STORES foo too
Exception: 1 is invalid input
>>>

Comments

taitumsabharwal said…
Borgata Hotel Casino & Spa - Jtm Hub
Find a room 목포 출장안마 at Borgata 성남 출장샵 Hotel Casino & 전주 출장샵 Spa 보령 출장안마 in Atlantic City, NJ. Choose from over 1,000 rooms, suites and villas, and read 347 전라남도 출장마사지 reviews. Rating: 4.2 · ‎347 reviews

Popular posts from this blog

Multiple repeat error when the regex has multiple wildcards in python re module

Avoid using global/class-level mutable datatypes like list/dicts

Weakref proxy is for instance only ...