Added some exception experiments I did.
They are to verify a detail we discussed with @qu1ck about a patch for IBoM. They aren't very interesting, but they are a playground to test Python 2/3 exception details.
This commit is contained in:
parent
520b9626b1
commit
1ba778f7f1
|
|
@ -0,0 +1,9 @@
|
|||
###########
|
||||
# Python 2:
|
||||
###########
|
||||
try:
|
||||
raise Exception
|
||||
except Exception as e:
|
||||
s, r = getattr(e, 'message') or str(e), getattr(e, 'message') or repr(e)
|
||||
print 's:', s, 'len(s):', len(s) # noqa: E999
|
||||
print 'r:', r, 'len(r):', len(r) # noqa: E999
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
try:
|
||||
raise Exception
|
||||
except Exception as e:
|
||||
s, r = getattr(e, 'message', str(e)), getattr(e, 'message', repr(e))
|
||||
print('s:', s, 'len(s):', len(s))
|
||||
print('r:', r, 'len(r):', len(r))
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
class ETest(Exception):
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
raise ETest("Hi!")
|
||||
except ETest as e:
|
||||
print(e)
|
||||
print(repr(e))
|
||||
print(type(e))
|
||||
print(e.__dict__)
|
||||
logging.debug(e)
|
||||
logging.error(e)
|
||||
logging.warning(e)
|
||||
logging.info(e)
|
||||
logging.critical(e)
|
||||
Loading…
Reference in New Issue