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 section called “PBDOM
exceptions” in PowerBuilder Extension Reference or the section called “Handling
PBDOM exceptions” in Application Techniques.
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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
Long ll_ret ll_ret = XMLParseFile(filename, ValNever!) if ll_ret < 0 then return PBDOM_Builder domBuilder TRY domBuilder = CREATE PBDOM_Builder PBDOM_Document domDoc PBDOM_Element root domDoc = domBuilder.BuildFromFile( filename ) IF IsValid( domDoc ) THEN IF domDoc.HasChildren() THEN PBDOM_Object data[] IF domDoc.GetContent( data ) THEN Long ll_index, ll_count ll_count = UpperBound( data ) FOR ll_index = 1 TO ll_count ProcessData( data[ll_index], 0 ) NEXT END IF END IF END IF CATCH ( PBDOM_Exception pbde ) MessageBox( "PBDOM Exception", pbde.getMessage() ) CATCH ( PBXRuntimeError re ) MessageBox( "PBNI Exception", re.getMessage() ) END TRY |