Error Handling¶
libxml-ruby reports errors through the XML::Error exception class. Errors from parsing, validation, and other operations all use this class.
Catching Errors¶
Error Properties¶
XML::Error provides detailed information:
rescue XML::Error => e
e.message # human-readable message
e.domain # error domain (e.g., XML::Error::PARSER)
e.code # error code
e.level # severity (WARNING, ERROR, FATAL)
e.file # source file
e.line # line number
e.node # related node (if available)
e.str1 # additional context
end
Error Levels¶
XML::Error::NONE # no error
XML::Error::WARNING # warning
XML::Error::ERROR # recoverable error
XML::Error::FATAL # fatal error
Custom Error Handler¶
Set a global error handler to capture errors that don't raise exceptions (such as validation warnings):
To reset to the default handler: