Handling Exceptions
The following sections document how to handle parse and DOM exceptions.
Handling Mapping Exceptions
Mapping exceptions are described using instances of the AbtXmlMappingError class. By default, mapping exceptions are NOT signalled. To enable signalling of mapping exceptions, execute the following code:
AbtXmlMappingError enableExceptionSignal: true
Enabling mapping exceptions is especially useful during initial construction of the mapping specification because it allows mapping errors to be more easily detected and debugged. An SgmlException will be signalled and will contain the AbtXmlMappingError that describes the problem. In order to simplify debugging, the domElement and mapping are saved with the AbtXmlMappingError instance.
Handling Parse Exceptions
If the XML parser detects errors while parsing an XML stream, the errors are reported by signaling exceptions. The exception class SgmlException is used to report errors. Exceptions will cause termination of the parse process unless they are handled by the application.
The following example shows an XML parser exception handler that writes error information to the Transcript. After an error is handled, the parser attempts to continue parsing.
[ AbtXmlDOMParser newValidatingParser parseURI: 'bogus.xml' ]
when: SgmlExceptions::SgmlException
do: [ :aSignal |
Transcript cr; show: aSignal argument printString ].
Handling DOM Exceptions
Exceptions that occur while manipulating the DOM are reported using the exception class AbtDOMException.
"An exception is reported for the case below because of a mismatch in the
'ownerDocument' property for the two elements."
[ ( AbtDOMDocument new createElement: 'test' )
appendChild: AbtDOMElement new ]
when: AbtDOMConstants::AbtDOMException
do: :aSignal |
Transcript cr; show: aSignal argument printString ].
Last modified date: 01/29/2015