I have the following simple piece of code to parse a reSt file and return the corresponding DOM tree.
from docutils import nodes, utils
from docutils.parsers import rst
def _rst_to_dom(self, txt):
"""Parse reStructuredText and return corresponding DOM tree."""
document = utils.new_document("Doc")
document.settings.tab_width = 4
document.settings.pep_references = 1
document.settings.rfc_references = 1
document.settings.raw_enabled = True
document.settings.file_insertion_enabled = True
rst.Parser().parse(txt, document)
return document.asdom()
This works great, but when the parser finds some problem with the input, instead of raising an exception so that my program knows that there is something wrong, it simply prints out an error message to the standard output and returns a tree with what it could do. How can I get it to raise an exception? Or, how can I know that something was amiss?