Page 1 of 1

Extending Exception

Posted: Wed Apr 23, 2008 5:20 pm
by aliasxneo
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:

Code: Select all

throw new FatalError("Invalid ID");
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:

Code: Select all

function test()
{
    throw new SilentError("Could not connect to service");
}
 
try {
    test();
} catch (Exception $e) {
 
}
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.

Re: Extending Exception

Posted: Tue Aug 26, 2008 11:02 am
by ericm
I don't have an answer to this myself, but am in the same predicament. Did you come up with a solution? Otherwise, maybe a bump will get more responses.