return values for exceptions
holger krekel
pyth at devel.trillke.net
Mon Nov 18 18:44:25 EST 2002
N. Thomas wrote:
> I notice that user defined Python exceptions always return a value of 1 to
> the shell. I'd like to return different values in my program, depending on
> the exception, is there any way to do this?
>
> I suppose that I could trap the exception, and then return a value based on
> that, but I'm not too sure if that is the right way to go about doing it.
IMO it's quite right. You could also derive from SystemExit:
>>> class MyEx(SystemExit):
pass
>>> raise MyEx(12) # this cleanly exists
$ echo $?
12
regards,
holger
More information about the Python-list
mailing list