Catching errors during error handling

Started by
2 comments, last by Mr Cucumber 21 years, 2 months ago
Right now my application works like this. The only way to shutdown the application is by throwing a Shutdown() or an Error(). The Error class is derived from the Shutdown class which allows me to only catch a Shutdown. Lets say the application starts the shutdown process in the catch part, and an Error occurs? What I am supposed to do with that throw, use another try-catch inside the other catch? And then if an error occurs in that catch what about then? Basically what I want is that the application does a normal good shutdown in case of an error. But the problem is if another error occurs when the error has been caught and the shutdown process has started.
Advertisement
You shutdown by throwing an error?

Exceptions are supposed to be used for exceptional cicumstances - it is not exceptional for someone to want to shut down your sofware.

Have you derived Error from the Shutdown class purely so that you only have to have one catch statement ie catch(Shutdown& e). That''s not a good reason for setting up a hierarchy.

Actually a thought - it''s just starting to nag at me - are you a java programmer?
I think he is using Shutdown to indicate an unrecoverable error that requires termination of the application. The only problem with that is that the caller should make that determination.

Generally an error handler should not generate an error because it hides the original error. That isn''t to say you don''t throw an error, but rather you throw the original or a reinterpretation of the original, i.e. a more descriptive error. You have to use your judgement though. You could run into an unrelated error such as an inability to write to the log that is a higher priority problem than the original error, i.e. the problem with the log needs to be fixed first. You can use an error class that is a container so that you don''t have to decide which of multiple errors to report.
Keys to success: Ability, ambition and opportunity.
You are probably right that I should not exit the application with an exception, and no I''m not a Java programmer (probably just bad programming habits).

Its actually not the error handler itself that can throw an error. When the error is caught I start the shutdown process.
Since there can be quite a lot of code in the shutdown process (for example save states to a file, close window and more) I need to check for errors during the shutdown process.

Perhaps the best way is to remove the shutdown process from the error handling and just do the absolutely necessary when the error is caught.

This topic is closed to new replies.

Advertisement