[Tutor] Regarding Exceptions
Chris “Kwpolska” Warrick
kwpolska at gmail.com
Mon Feb 17 15:06:26 CET 2014
On Mon, Feb 17, 2014 at 12:44 PM, Khalid Al-Ghamdi <emailkgnow at gmail.com> wrote:
> Hi,
>
> Why is it i can use mu custom class exception without creating an exception
> object first?
>
> Thanks
>
> class ShortInputException(Exception): def __init__(self, length, atleast):
> Exception.__init__(self)
> self.length = length
> self.atleast = atleast
> try:
> text = input() if len(text) < 3:
> raise ShortInputException(len(text), 3) # Other work can continue as usual
> here
> except EOFError:
> print()
> except ShortInputException as ex:
> print(\
> .format(ex.length, ex.atleast)) else:
> print()
Hello there!
Unfortunately, the code you provided is invalid, and it seems not to
contain required indentation, newlines, and has some other things that
should break (eg. line 12)
Please reply (using Reply All!) in plaintext, with the correct code.
Also, do you mind phrasing your question more precisely? Do you need
help with inheritance? What is the problem you’re having?
--
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
More information about the Tutor
mailing list