[Tutor] Regarding Exceptions

Khalid Al-Ghamdi emailkgnow at gmail.com
Mon Feb 17 12:44:36 CET 2014


Hi,

Why is it i can use mu custom class exception without creating an exception
object first?

Thanks


   1. class ShortInputException(Exception): def __init__(self, length,
    atleast):
   2.         Exception.__init__(self)
   3.         self.length = length
   4.         self.atleast = atleast
   5. try:
   6. text = input() if len(text) < 3:
   7. raise ShortInputException(len(text), 3) # Other work can continue as
   usual here
   8. except EOFError:
   9. print()
   10. except ShortInputException as ex:
   11. print(\
   12. .format(ex.length, ex.atleast)) else:
   13. print()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140217/e54ec087/attachment-0001.html>


More information about the Tutor mailing list