Error handling changes.

- Install error handlers before functions using them, so they're installed on the relevant thread.
- Build error instance in error handler, rather than relying on pointer remaining valid.
- Extract libxml2 error when parsing an XML document, attach to existing error as an underlying error.