Pregunta

I am writing a loader program to decrypt source files and run them. Each source file holds a Curses::UI based program which contain subroutines that the user may use to exit the user interface. I need to run some clean up after the user exits though and am not sure how to catch these exit or die calls so the clean-up code that comes after the required files will execute, any ideas?

¿Fue útil?

Solución

You can catch die calls by wrapping the code in an eval block, as in:

eval {
    require Module::that_dies;
};
if ($@) {
    # handle the exception here
}

This won't help for exit though. You could have code that runs to cleanup after exit in an END{} block, I believe, but note that this will be run after any exit, not just if your required module exits.

END { 
    # code that runs after exit
}

require Module::that_exits;

Read more about END blocks in perldoc perlmod

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top