Python/Exception: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
No edit summary
Line 13: Line 13:
</source>
</source>


=== traceback ===
=== traceback.print_exc ===


<source lang="python">
<source lang="python">

Revision as of 03:50, 26 September 2019

except ... as ex:

try:
    n = 1 / 0
except Exception as ex:
    print('It sucks!')
    print('Class: {}'.format(type(ex).__name__))
    print('Message: {}'.format(ex))
    print('Args:')
    for arg in ex.args:
        print('    {}'.format(arg))

traceback.print_exc

import traceback

def c():
    n = 1 / 0

def b():
    c()

def a():
    b()

if __name__ == '__main__':
    try:
        a()
    except:
        traceback.print_exc()