/
diev
/
swaroopch-byte-of-python
Обзор
Документация
Войти
/
diev
/
swaroopch-byte-of-python
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
programs/exceptions_raise.py
20 строк
651 B
Swaroop C H
Add programs folder
19 янв 2016, 18:47
19 янв 2016, 18:47
ed99d1b
Код
Авторство
О чём код?
class ShortInputException(Exception): '''A user-defined exception class.''' def __init__(self, length, atleast): Exception.__init__(self) self.length = length self.atleast = atleast try: text = input('Enter something --> ') if len(text) < 3: raise ShortInputException(len(text), 3) # Other work can continue as usual here except EOFError: print('Why did you do an EOF on me?') except ShortInputException as ex: print(('ShortInputException: The input was ' + '{0} long, expected at least {1}') .format(ex.length, ex.atleast)) else: print('No exception was raised.')