DOM guide: Error handling: Difference between revisions

From COLLADA Public Wiki
Jump to navigation Jump to search
Alorino (talk | contribs)
No edit summary
Elf (talk | contribs)
basic copy edit
Line 1: Line 1:
The [[COLLADA DOM]] provides an interface, ''daeErrorHandler'', that handles the printing error messages.
The [[COLLADA DOM]] provides an interface, '''daeErrorHandler''', that handles the printing of error messages.


==Overview==
==Overview==
The daeErrorHandler is an abstract singleton class. That is the functionality must implemented in a subclass but only one instance of any subclass will be active and available through the daeErrorHandler interface.
The '''daeErrorHandler''' is an ''abstract singleton'' class. That is, the functionality must be implemented in a subclass (''abstract'') but only one instance of any subclass will be active and available (''singleton'') through the '''daeErrorHandler''' interface.


The [[COLLADA DOM]] provides a default daeErrorHandler implementation, daeStdErrPlugin. The daeStdErrPlugin class implements daeErrorHandler and routes the string error messages to C standard error stream.
The [[COLLADA DOM]] provides a default '''daeErrorHandler''' implementation, '''daeStdErrPlugin'''. The '''daeStdErrPlugin''' class implements '''daeErrorHandler''' and routes string error messages to the C standard error stream.


==Creating Your Own Error Handler==
==Creating Your Own Error Handler==
It may be desirable to route error messages for special handling or because the C standard error stream is unavailable, like in GUI programs. You can create your own error handling code by implementing a class that inherits from daeErrorHandler.
It may be desirable to route error messages for special handling or because the C standard error stream is unavailable, such as in GUI programs. You can create your own error-handling code by implementing a class that inherits from '''daeErrorHandler'''.


The daeErrorHandler interface declares two functions that need to be implemented to handle messages:
The '''daeErrorHandler''' interface declares two functions that need to be implemented to handle messages:
handleError( daeString );
* '''handleError( daeString );'''
handleWarning( daeString );
* '''handleWarning( daeString );'''


Implement these functions to parse or route the messages as you see fit. An example would be to create a pop-up window with the error message.
Implement these functions to parse or route the messages in whatever way you want. An example would be to create a pop-up window with the error message.
 
After implementing your error-handling class, you must pass an object of your class to the '''daeErrorHandler''' class to notify the DOM to use it for error handling. Use the '''daeErrorHandler::setErrorHandler''' method to do this. For example:


After implementing your error handling class you must pass an object of your class to the daeErrorHandler class to be used for error handling. The daeErrorHandler::setErrorHandler method is used to specify a specific error handler to be used.
  DAE *daeObject = new DAE();
  DAE *daeObject = new DAE();
  myErrorHandlerClass *myEH = new myErrorHandlerClass();
  myErrorHandlerClass *myEH = new myErrorHandlerClass();
Line 23: Line 24:
  delete daeObject;
  delete daeObject;
  delete myEH;
  delete myEH;
Note that the daeErrorHandler does not destroy or free up any memory used by custom error handlers. You are responsible to destroy the error handler yourself.
Note that the '''daeErrorHandler''' does not destroy or free any memory used by custom error handlers. You are responsible for destroying the error handler yourself.


==Sending Error Messages To daeErrorHandler==
==Sending Error Messages to daeErrorHandler==
A client application is free to call the daeErrorHandler code to route their error messages.
A client application is free to call the daeErrorHandler code to route its error messages.
 
To send a message, you need to obtain a pointer to the active error handler by calling '''daeErrorHandler::get()'''. You can then call the appropriate error handling method. For example:


To send a message you need to obtain a pointer to the active error handler by calling daeErrorHandler::get(). You can then call the appropriate error handling method.
  daeErrorHandler::get()->handleError( "The data you are loading is broken. Go fix it and try again!" );
  daeErrorHandler::get()->handleError( "The data you are loading is broken. Go fix it and try again!" );
[[Category:DOM project]]

Revision as of 18:45, 27 March 2007

The COLLADA DOM provides an interface, daeErrorHandler, that handles the printing of error messages.

Overview

The daeErrorHandler is an abstract singleton class. That is, the functionality must be implemented in a subclass (abstract) but only one instance of any subclass will be active and available (singleton) through the daeErrorHandler interface.

The COLLADA DOM provides a default daeErrorHandler implementation, daeStdErrPlugin. The daeStdErrPlugin class implements daeErrorHandler and routes string error messages to the C standard error stream.

Creating Your Own Error Handler

It may be desirable to route error messages for special handling or because the C standard error stream is unavailable, such as in GUI programs. You can create your own error-handling code by implementing a class that inherits from daeErrorHandler.

The daeErrorHandler interface declares two functions that need to be implemented to handle messages:

  • handleError( daeString );
  • handleWarning( daeString );

Implement these functions to parse or route the messages in whatever way you want. An example would be to create a pop-up window with the error message.

After implementing your error-handling class, you must pass an object of your class to the daeErrorHandler class to notify the DOM to use it for error handling. Use the daeErrorHandler::setErrorHandler method to do this. For example:

DAE *daeObject = new DAE();
myErrorHandlerClass *myEH = new myErrorHandlerClass();
daeErrorHandler::setErrorHandler( myEH );
daeObject->load( myFileToLoad );
...
delete daeObject;
delete myEH;

Note that the daeErrorHandler does not destroy or free any memory used by custom error handlers. You are responsible for destroying the error handler yourself.

Sending Error Messages to daeErrorHandler

A client application is free to call the daeErrorHandler code to route its error messages.

To send a message, you need to obtain a pointer to the active error handler by calling daeErrorHandler::get(). You can then call the appropriate error handling method. For example:

daeErrorHandler::get()->handleError( "The data you are loading is broken. Go fix it and try again!" );