DOM guide: Error handling: Difference between revisions
basic copy edit |
No edit summary |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
The [[COLLADA DOM]] provides an interface, | The [[COLLADA DOM]] provides an interface, <code>daeErrorHandler</code>, that '''handles the printing of error messages'''. It allows a client application to be notified when the [[COLLADA DOM]] encounters an internal error. | ||
==Overview== | ==Overview== | ||
The | The <code>daeErrorHandler</code> 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 <code>daeErrorHandler</code> interface. | ||
The [[COLLADA DOM]] provides a default | The [[COLLADA DOM]] provides a default <code>daeErrorHandler</code> implementation, <code>daeStdErrPlugin</code>. The <code>daeStdErrPlugin</code> class implements <code>daeErrorHandler</code> 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, such as in GUI programs. You can create your own error-handling code by implementing a class that inherits from | 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 <code>daeErrorHandler</code>. | ||
The | The <code>daeErrorHandler</code> interface declares two functions that need to be implemented to handle messages: | ||
* | * <code>handleError( daeString );</code> | ||
* | * <code>handleWarning( daeString );</code> | ||
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. | 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 | After implementing your error-handling class, you must pass an object of your class to the <code>daeErrorHandler</code> class to notify the DOM to use it for error handling. Use the <code>daeErrorHandler::setErrorHandler</code> method to do this. For example: | ||
DAE *daeObject = new DAE(); | DAE *daeObject = new DAE(); | ||
Line 24: | Line 24: | ||
delete daeObject; | delete daeObject; | ||
delete myEH; | delete myEH; | ||
Note that the | Note that the <code>daeErrorHandler</code> 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 its error messages. | A client application is free to call the <code>daeErrorHandler</code> code to route its error messages. To send a message, get a pointer to the active error handler by calling <code>daeErrorHandler::get</code>. 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!" ); | |||
The <code>daeErrorHandler::get</code> method always returns a valid error handler, so there's no need to check the return value for NULL. | |||
{{DOM navigation}} | |||
[[Category:DOM | [[Category:COLLADA DOM|Error handling]] |
Latest revision as of 23:47, 6 February 2008
The COLLADA DOM provides an interface, daeErrorHandler
, that handles the printing of error messages. It allows a client application to be notified when the COLLADA DOM encounters an internal error.
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, get 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!" );
The daeErrorHandler::get
method always returns a valid error handler, so there's no need to check the return value for NULL.
COLLADA DOM - Version 2.4 Historical Reference |
---|
List of main articles under the DOM portal. |
User Guide chapters: • Intro • Architecture • Setting up • Working with documents • Creating docs • Importing docs • Representing elements • Working with elements • Resolving URIs • Resolving SIDs • Using custom COLLADA data • Integration templates • Error handling Systems: • URI resolver • Meta • Load/save flow • Runtime database • Memory • StringRef • Code generator |