Guest User

Untitled

a guest
Jun 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. raise Exception("Hello world")
  2. Traceback (most recent call last):
  3.  
  4. File "<ipython-input-24-dd3f3f45afbe>", line 1, in <module>
  5. raise Exception("Hello world")
  6.  
  7. Exception: Hello world
  8.  
  9. str(foo)
  10. Out[27]: 'Hello world'
  11.  
  12. repr(foo)
  13. Out[28]: "Exception('Hello world',)"
  14.  
  15. "{}".format(foo)
  16. Out[29]: 'Hello world'
  17.  
  18. "{}: {}".format(type(foo), foo)
  19. Out[30]: "<type 'exceptions.Exception'>: Hello world"
  20.  
  21. print('{}: {}'.format(type(exc).__name__, exc))
  22.  
  23. #test.py
  24. import traceback
  25.  
  26. try :
  27. raise TypeError("Wrong Type baby!")
  28.  
  29. except Exception, e:
  30. print( "EXCEPTION FORMAT PRINT:n{}".format( e ) )
  31. print( "EXCEPTION TRACE PRINT:n{}".format( traceback.format_exc(e) ) )
  32.  
  33. EXCEPTION FORMAT PRINT:
  34. Wrong Type baby!
  35. EXCEPTION TRACE PRINT:
  36. Traceback (most recent call last):
  37. File "/Users/me/test.py", line 4, in <module>
  38. raise TypeError("Wrong Type baby!")
  39. TypeError: Wrong Type baby!
Add Comment
Please, Sign In to add comment