mirror of
https://github.com/valitydev/yamerl.git
synced 2024-11-06 10:55:16 +00:00
15096b6053
PR: #837
1.1 KiB
1.1 KiB
yamerl 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
, eithererror
orwarning
;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: