Advertisement
AZJIO

Установка ошибок функции

Sep 23rd, 2014
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. # coding: utf8
  2.  
  3. class MyException(Exception):
  4.    pass
  5.  
  6. def name_func():
  7.     x = 1
  8.     if x > 10:
  9.         raise MyException('Большое')
  10.     if x < 3:
  11.         raise MyException('Маленькое')
  12.     if x == 7:
  13.         raise MyException('Нормально', 'arg1', 'arg2')
  14.     print 'fff'
  15.  
  16. try:
  17.     name_func()
  18. except MyException as e:
  19.     print e.message
  20.  
  21. try:
  22.     name_func()
  23. except MyException as e:
  24.     print e.args
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement