Extending Exception
Posted: Wed Apr 23, 2008 5:20 pm
I've been pondering this in my head for quite awhile and can't seem to come up with any logical conclusions to this issue:
The way I wish to implement error handling in my application is through exceptions. I want two distinct classes that both extend exception, FatalError and SilentError. FatalError is simply that, a fatal error from which the application cannot recover and should be reported immediatly. A SilentError is an error which does not hinder the application from moving forward but at the same time should be logged somewhere.
For FatalError when the exception is throw such as:
The FatalError construct function would render the error message and stop the script with die(). Thus the exception does not need to be caught.
When looking at SilentError the issue arises in how can it be thrown but not have to be caught at the same time? All SilentError should do in the constructor is log the error somewhere and then move on with the script. The whole idea behind this method is so that errors are handled in the background and I do not have to directly handle them.
If I were to be forced to catch the SilentError's it would be a complete waste of code:
Since all the handling happens in the constructor of SilentError I end up with a blank pointless try/catch statement. So my question is does anyone see any a way around this?
By the way, the entire reason I even want to use exceptions is because I want access to information like the file and line the error occurred on as well as the stack trace.
The way I wish to implement error handling in my application is through exceptions. I want two distinct classes that both extend exception, FatalError and SilentError. FatalError is simply that, a fatal error from which the application cannot recover and should be reported immediatly. A SilentError is an error which does not hinder the application from moving forward but at the same time should be logged somewhere.
For FatalError when the exception is throw such as:
Code: Select all
throw new FatalError("Invalid ID");When looking at SilentError the issue arises in how can it be thrown but not have to be caught at the same time? All SilentError should do in the constructor is log the error somewhere and then move on with the script. The whole idea behind this method is so that errors are handled in the background and I do not have to directly handle them.
If I were to be forced to catch the SilentError's it would be a complete waste of code:
Code: Select all
function test()
{
throw new SilentError("Could not connect to service");
}
try {
test();
} catch (Exception $e) {
}By the way, the entire reason I even want to use exceptions is because I want access to information like the file and line the error occurred on as well as the stack trace.