Handling PBDOM exceptions
PBDOM defines an exception class, PBDOM_EXCEPTION,
derived from the standard PowerBuilder Exception class. The standard
Text property of the Exception class can be used to obtain more
detail on the nature of the exception being thrown. The class extends
the PowerBuilder Exception class with one method, GetExceptionCode, that
returns the unique code that identifies the exception being thrown.
For a list of exception codes, see the PowerBuilder
Extension Reference or the topic PBDOM exceptions in
the online Help.
PBDOM is a PowerBuilder extension, built using PBNI. The extension
itself might throw a PBXRuntimeError exception. In the following
example, the try–catch block checks first for a PBDOM exception,
then for a PBXRuntimeError.
The example builds a PBDOM_DOCUMENT from a passed-in
file name and uses a user-defined function called ProcessData to
handle the DOM nodes. ProcessData could be a
recursive function that extracts information from the DOM elements
for further processing:
1 |
Long ll_ret<br> <br>ll_ret = XMLParseFile(filename, ValNever!)<br>if ll_ret < 0 then return<br> <br>PBDOM_Builder   domBuilder<br> <br>TRY<br>   domBuilder = CREATE PBDOM_Builder<br>   PBDOM_Document domDoc<br>   PBDOM_Element   root<br>   domDoc = domBuilder.BuildFromFile( filename )<br>   IF IsValid( domDoc ) THEN<br>      IF domDoc.HasChildren() THEN<br>         PBDOM_Object data[]<br>         IF domDoc.GetContent( data ) THEN<br>            Long   ll_index, ll_count<br>            ll_count = UpperBound( data )<br>            FOR ll_index = 1 TO ll_count<br>               ProcessData( data[ll_index], 0 )<br>            NEXT<br>         END IF<br>      END IF<br>   END IF<br> <br>CATCH ( PBDOM_Exception pbde )<br>   MessageBox( "PBDOM Exception", pbde.getMessage() )<br>CATCH ( PBXRuntimeError re )<br>   MessageBox( "PBNI Exception", re.getMessage() )<br>END TRY |