[Novalug] error handling in perl
James Ewing Cottrell III
JECottrell3@Comcast.NET
Sun Dec 1 20:55:13 EST 2013
Um...why do you need to Destroy an Object if you are going to Exit?!?
Unless you were in the middle of the 'open_control_rods' subroutine, I'd
just let Exit cleanup for you.
JIM
On 11/24/2013 9:30 PM, Mark Smith wrote:
> so, imagine this if you will... there is a perl function that does a
> bunch of stuff, creates, objects, destroy objects, and does some meat in
> between. BUT, what if someone types ^C after the object has been created.
> the object was created within a sub call and hence there's a variable
> with local scope pointing to the object. the handler identified within
> $SIG{INTR} is called. how does one clean up under ^C.
>
> for instance:
>
> sub scope
> {
> my $fileid;
>
> ... create file
> ... do stuff that takes a minute
> ... destroy file
> }
>
> sub cleanup
> {
> ... stuff ...
> exit 1;
> }
>
> $SIG{INT} = \&cleanup;
>
> scope();
>
> i know of three ways of dealing with the local scope issue:
>
> 1. make the local scope global and deal with it there.
> 2. make the interrupt function set a variable and return and let the
> subroutine deal with it at the correct time.
> 3. do some magic with eval.
>
> i'm not terribly enamoured with any method above for various reasons.
> can anyone think of something else?
>
More information about the Novalug
mailing list