[studxml-users] Asserts in next_expect functions

Pedro Calixto pedro at kryptus.com
Wed Oct 18 13:52:08 EDT 2017


There is a difference, however, between these assertion placements.

To test it, I moved the assertion found in /inline void
parser::next_expect (event_type e, const std::string& ns, const
std::string& n, //content_type c)/ (parser.ixx) to the beginning of this
function.


The parsed xml was:

<?xml version="1.0" encoding="utf-8"?>
<person id="123">
  <name>John Doe</name>
</person>


The code that tested it was:

int main(int argc, char *argv[]) {

  std::ifstream ifs(argv[1]);
  xml::parser p(ifs, argv[1]);

  std::string const Name("animal");
  std::string const Ns("");
  auto Content = xml::content(xml::content::complex);
  p.next_expect(xml::parser::end_element, Ns, Name, Content);

  return 0;
}


Before moving the assertion to the beginning, there was an exception
thrown (parsing), and the program output was:

terminate called after throwing an instance of 'xml::parsing'
  what():  error.xml:2:0: error: end element 'animal' expected
Aborted (core dumped)

After moving the assertion to the beginning, there was no exception, but
the assertion error:

main: /usr/local/include/xml/parser.ixx:136: void
xml::parser::next_expect(xml::parser::event_type, const string&, const
string&, xml::parser::content_type): Assertion `e == start_element' failed.
Aborted (core dumped)

I wonder which alternative would be better for displaying the error to
the user, since the exception description feels more clear about what
was wrong (IMO).

-- 
Pedro Calixto,
Estagiário
KRYPTUS EED S/A
Trust in Cybersecurity
+55 19 3112 5000
www.kryptus.com



More information about the studxml-users mailing list