Any time my program stops execution (either when shut down by cmd-c or when it encounters an exception), I want to take a few actions to shut down properly.
When I do cmd-c, I receive the signal TERM. What signal is sent when the program encounters an exception that is raised? How do I trap this with Signal.trap(…)?
You could wrap your code in a
begin-ensure-endblock. It would catch exceptions and CTRL-C. (You could add a rescue clause before theensure).