Rational Developer for System z
COBOL for Windows, Version 7.5, Programming Guide


Handling exceptions that the XML parser finds

If the exception code that the XML parser passes in XML-CODE is within a certain range, you can handle the exception event with a processing procedure.

To handle an exception event in your processing procedure, do these steps:

  1. Check the contents of XML-CODE.
  2. Handle the exception as appropriate.
  3. Set XML-CODE to zero to indicate that you handled the exception.
  4. Return control to the parser. The exception condition then no longer exists.

You can handle exceptions this way only if the exception code that is passed in XML-CODE is within one of the following ranges, which indicate that an encoding conflict was detected:

You can do limited handling of exceptions for which the exception code passed in XML-CODE is within the range 1-49. After an exception in this range occurs, the parser does not signal any further normal events, except the END-OF-DOCUMENT event, even if you set XML-CODE to zero before returning. If you set XML-CODE to zero, the parser continues parsing the document and signals any exceptions that it finds. (Doing so can be useful as a way of discovering multiple errors in the document.) At the end of parsing after an exception in this range, control is passed to the statement that you specify in the ON EXCEPTION phrase, if any, otherwise to the end of the XML PARSE statement. The special register XML-CODE contains the code for the most recent exception that the parser detected.

For all other exceptions, the parser signals no further events, and passes control to the statement that you specify in the ON EXCEPTION phrase. In this case, XML-CODE contains the original exception number even if you set XML-CODE to zero in the processing procedure before returning control to the parser.

If you do not want to handle an exception, return control to the parser without changing the value of XML-CODE. The parser transfers control to the statement that you specify in the ON EXCEPTION phrase. If you do not code an ON EXCEPTION phrase, control is transferred to the end of the XML PARSE statement.

If you return control to the parser with XML-CODE set to a nonzero value that is different from the original exception code, the results are undefined.

If no unhandled exceptions occur before the end of parsing, control is passed to the statement that you specify in the NOT ON EXCEPTION phrase (normal end of parsing). If you do not code a NOT ON EXCEPTION phrase, control is passed to the end of the XML PARSE statement. The special register XML-CODE contains zero.

related concepts
How the XML parser handles errors
The content of XML-CODE

related tasks
Writing procedures to process XML
Understanding the encoding of XML documents
Handling conflicts in code pages

related references
XML PARSE exceptions that allow continuation
XML PARSE exceptions that do not allow continuation
XML-CODE (COBOL for Windows Language Reference)


Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)