[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
ERROR HANDLER Install a class error handler method
---------------------------------------------------------------------------------
SYNTAX:
ERROR HANDLER < cMethod( cMessage, nError )>
PARAMETER:
<cMethod> Is the Method name of our Error Handler Method. It will be
called with two arguments :
aMethod : the Error Description as a String
nError : the ErrorCode (found in "ObjError.ch")
DESCRIPTION:
This Command declares an Error handler Method for the defined Class. Every
time now that an an error ocurrs managing an Object of this class your
Error Handler takes control. Your Error handler is then responsible to
discard the error, or create a Clipper runtime error via _ClsSetError().
You can define an Error handler on each Class.
This feature is extremelly powerfull for adding extra functionality to
to certain Classes. Basically, you can have same Class Objects with
different behaviors without having to inherit new classes ( take a look
at DATABASE.PRG, where the Error Handler is used to determine the target
Field ).
EXAMPLE:
+--------------------------------------------------------------+
| /* Define an Error handler */ |
| |
| CREATE CLASS TSTRING |
| |
| VAR cStr AS CHAR |
| [ ... ] |
| METHOD new( c ) |
| INLINE ( ::cStr := c, Self ) |
| |
| ERROR HANDLER ; |
| OnError( cMsg, nErr ) |
| |
| ENDCLASS |
| |
| |
| METHOD OnError( cMethod, nError ) |
| |
| /* Ignore this Error */ |
| IF nError == NO_EXPORTED .AND. ; |
| ALLTRIM( UPPER( cMethod )) == "NOERROR" |
| RETURN "OK" |
| |
| /* Special Error */ |
| ELSEIF nError == 99 |
| MsgInfo( "Wrong, Slaphead !" ) |
| RETURN "OK" |
| |
| /* Launch Runtime Error on the rest */ |
| ELSE |
| _ClsSetError( ; |
| _GenError( nError, ::ClassName, cMethod )) |
| ENDIF |
| |
| RETURN nil |
| |
| |
| PROCEDURE TestError() |
| LOCAL ; |
| oString := TSTRING():New( "String" ) |
| |
| /* This would normaly bomb the App, but is ignored now */ |
| ? oString:cNotThere |
| |
| /* This creates a special Message */ |
| _ClsSetError( 99 ) |
| |
| RETURN |
| |
+--------------------------------------------------------------+
See Also:
_GenError
_ClsSetError
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson