Error Suppression

Is it possible to extend the Exception class or otherwise create class error handling that would allow for "@" error supression of my written class.

In other words:

$myInstance->myMethod(); //This returns the error message, but
@$myInstance->myMethod(); //this suppresses the error message...

in the same fashion as with PHP functions.

If someone knows where I can find an article or posting on the subject, that would be great. I have not found one...

Thanx
StevenThat is what the try and catch statements are for.Using the @ operator doesn't stop exceptions being thrown. This is what try is for.

On the other hand, the @ operator should be used VERY sparingly, because (stupidly), it even suppresses fatals but doesn't stop them from being fatal, thus causing a "blank page" error.

If you write a custom error handler, you can make it take into account error_reporting() (and indeed you should). But that won't apply to fatals.

If you make a custom error handler, but you have an operation which can issue one or more warnings and still succeed (e.g. parsing a HTML document), try / catch won't help, as the act of throwing the exception aborts the operation. Another error handling strategy is necessary then.

Mark
 
Back
Top