how to get a return value from an exception ?

Chris Liechti cliechti at gmx.net
Thu Jul 25 11:18:11 EDT 2002


"Shagshag13" <shagshag13 at yahoo.fr> wrote in
news:ahp28b$uccl1$1 at ID-146704.news.dfncis.de: 

> i had another questions :
> 
> * if exceptionB and exceptionC subclass from exceptionA, if i raise
> exceptionB i could still catch it as it was ExceptionA ?

you mean that:
try:
    	raise exceptionC()
except exceptionA, ex:
    	print "gotcha"

gets the exception, yes.

> * is it a
> correct statement ? :
> try:
>     #do
> except exceptionB:
>     #do 1
> except exceptionC:
>     #do 2
> except exceptionA:
>     #do else

yes. and you have the correct order: subclasses first, and below the 
baseclass. (otherwise the baseclass would catch everything)

chris

PS: i would start class names, like ExceptionB with capital letters. coding 
style conventions - you know.

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list