I have some sample code below, where I create an object then throw an exception.
import sys
class Abc(object):
def __init__(self):
pass
def __del__(self):
print('>>>>>>>>>>>>del')
sys.exit(12)
print('before')
a = Abc()
print('after')
raise Exception('asd')
Output:
before
after
Traceback (most recent call last):
File "C:\development\test.py", line 13, in <module>
raise Exception('asd')
Exception: asd
>>>>>>>>>>>>del
Exception ignored in: <bound method Abc.__del__ of <__main__.Abc object at 0x007E2BB0>>
Traceback (most recent call last):
File "C:\development\aft-system\components\Core\src\python\PythonAPI\sel\aft\tests\regression_tests\exit_code_tests\test.py", line 9, in __del__
SystemExit: 12
As you can see, the destructor is called, but I can't seem to get a debugger in there. I'd like to get access to the exception and change the exit code if possible.
As you can see, the the sys.exit is called, but that throws an exception which is ignored by the current exception.
I should note that I can't wrap this in a try/catch as it's just a library for someone else to use. This scenario is for when an exception happens in the caller or some other library.
Any thoughts?