On Thu, Apr 05, 2007, Mike Hansen wrote:
>When doing a try/except block, is it possible to return a list as part
>of the exception?
>
>try:
> check_someting()
>except CheckSomethingError, e:
> for each_error in e:
> # do something
>
>Can 'e' be a list of errors? If so, how do you construct your exception
>class?
If the Exception is defined as a class, e will be an instance of
that class so you can have pretty much anything available:
class MyException(Exception):
def __init__(self, msg, mylist)
self.msg = msg
self.mylist = mylist
Exception.__init__(self, msg)
try:
check_something()
except MyException, e:
for entry in e.mylist: ...
Bill
--
INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
``I don't make jokes, I just watch the Government and report the facts...''
Will Rogers
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor