Recipe: Error handling
yamerl throws an exception when an error occurs.
- Start the yamerl application. This is a mandatory step.
application:start(yamerl).
- You’re now ready to parse a serialized document:
To parse an in-memory string or binary:
-include_lib("yamerl/include/yamerl_errors.hrl"). % ... try Documents = yamerl_constr:string("Hello!"), % Documents is a list of constructed documents. Documents catch throw:#yamerl_exception{errors = Errors} -> % Do something with the exception. Errors end.
As you can see, the #yamerl_exception{} record embeds all encountered errors:
#yamerl_exception{
errors = [] % List of errors.
}.
Errors are records where the two first members are always:
type, eithererrororwarning;text, a human-readable error message.
Following members depend on the error record. Two records are currently defined:
#yamerl_invalid_option{};#yamerl_parsing_error{}.
For further informations, see: