Python/Exception: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
(Created page with "<source lang="python"> try: n = 1 / 0 except Exception as e: print('It sucks!') print('Class: {}'.format(type(e).__name__)) print('Message: {}'.format(e))...")
 
No edit summary
Line 9: Line 9:
     for arg in e.args:
     for arg in e.args:
         print('    {}'.format(arg))
         print('    {}'.format(arg))
</source>
<source lang="python">
import traceback
def c():
    n = 1 / 0
def b():
    c()
def a():
    b()
if __name__ == '__main__':
    try:
        a()
    except:
        traceback.print_exc()
</source>
</source>

Revision as of 03:48, 26 September 2019

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

def c():
    n = 1 / 0

def b():
    c()

def a():
    b()

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