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:
SET 2020-08-19 11:47:09 -03:00
parent 520b9626b1
commit 1ba778f7f1
3 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -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))

View File

@ -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)