Advertisement
wagner-cipriano

Handling exceptions and cleanup code in python

Oct 16th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. from __future__ import print_function      #Compatibilidade func print python 2/3
  2. #Handling exceptions and cleanup code in python
  3.  
  4. #try...except...finally
  5. try:
  6.     a = 1; b = 0;
  7.     c = a/b;
  8. except Exception as ErrMsg:
  9.     print ('ErrMsg:', ErrMsg)
  10. finally:
  11.     print ('Always do it 1')
  12.  
  13.  
  14. #try...finally
  15. try:
  16.     a = 1; b = 0;
  17.     #c = a/b;
  18. finally:
  19.     print ('Always do it 3')
  20.  
  21.  
  22. #try...except
  23. try:
  24.     a = 1; b = 0;
  25.     c = a/b;
  26. except:
  27.     print ('Ocorreu um erro generico!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement