[Tutor] raise exception works as planned in program but not when imported into testing module
Jim Mooney Py3.4.3winXP
cybervigilante at gmail.com
Thu Apr 30 08:04:16 CEST 2015
On 29 April 2015 at 21:14, Dave Angel <davea at davea.name> wrote:
> But why are you surprised? There's no try/except protecting the latter
> line, so the exception will be uncaught, and you'll see it reported in
> parse_string().
>
I think I meant something like this. An exception in a function is caught
by the caller. I imported the program that did this into the test program,
expecting the exception to still be caught when the parse_string was
called, by the try except else block in the mainroutine of the imported
program..
def excepter():
raise ValueError
try:
excepter()
except ValueError:
print("Exception caught after function call")
REPL
>>>
Exception caught after function call
>>>
--
Jim
"What a rotten, failed experiment. I'll start over. Maybe dogs instead of
monkeys this time." --God
More information about the Tutor
mailing list