diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-06-18 20:14:40 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-06-19 11:52:11 +0100 |
commit | 8a22a7a76be8d9b439ee73383edbdf9d554bf3eb (patch) | |
tree | 116733ff35f20dddb247c412c842256cef68f5af /pdf/pdf_parse.c | |
parent | fe0be86de83b44ace49ceb540fc7f9e4db8253fb (diff) | |
download | mupdf-8a22a7a76be8d9b439ee73383edbdf9d554bf3eb.tar.xz |
Exception handling changes
In preparation for work on progressive loading, update the exception
handling scheme slightly.
Until now, exceptions (as thrown with fz_throw, and caught with
fz_try/fz_catch) have merely had an informative string. They have
never had anything that can be compared to see if an error is of
a particular type.
We now introduce error codes; when we fz_throw, we now always
give an error code, and can optionally (using fz_throw_message)
give both an error code and an informative string.
When we fz_rethrow from within a fz_catch, both the error code and
the error message is maintained. Using fz_rethrow_message we can
'improve' the error message, but the code is maintained.
The error message can be read out using fz_caught_message() and the
error code can be read as fz_caught().
Currently we only define a 'generic' error. This will expand in future
versions to include other error types that may be tested for.
Diffstat (limited to 'pdf/pdf_parse.c')
-rw-r--r-- | pdf/pdf_parse.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c index b50e1094..18ab3113 100644 --- a/pdf/pdf_parse.c +++ b/pdf/pdf_parse.c @@ -292,7 +292,7 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) case PDF_TOK_R: if (n != 2) - fz_throw(ctx, "cannot parse indirect reference in array"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse indirect reference in array"); obj = pdf_new_indirect(ctx, a, b, xref); pdf_array_push(ary, obj); pdf_drop_obj(obj); @@ -352,7 +352,7 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; default: - fz_throw(ctx, "cannot parse token in array"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse token in array"); } } end: @@ -362,7 +362,7 @@ end: { pdf_drop_obj(obj); pdf_drop_obj(ary); - fz_throw(ctx, "cannot parse array"); + fz_rethrow_message(ctx, "cannot parse array"); } return op; } @@ -396,7 +396,7 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; if (tok != PDF_TOK_NAME) - fz_throw(ctx, "invalid key in dict"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid key in dict"); key = pdf_new_name(ctx, buf->scratch); @@ -444,10 +444,10 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; } } - fz_throw(ctx, "invalid indirect reference in dict"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid indirect reference in dict"); default: - fz_throw(ctx, "unknown token in dict"); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown token in dict"); } pdf_dict_put(dict, key, val); @@ -462,7 +462,7 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) pdf_drop_obj(dict); pdf_drop_obj(key); pdf_drop_obj(val); - fz_throw(ctx, "cannot parse dict"); + fz_rethrow_message(ctx, "cannot parse dict"); } return dict; } @@ -488,7 +488,7 @@ pdf_parse_stm_obj(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) case PDF_TOK_FALSE: return pdf_new_bool(ctx, 0); break; case PDF_TOK_NULL: return pdf_new_null(ctx); break; case PDF_TOK_INT: return pdf_new_int(ctx, buf->i); break; - default: fz_throw(ctx, "unknown token in object stream"); + default: fz_throw(ctx, FZ_ERROR_GENERIC, "unknown token in object stream"); } return NULL; /* Stupid MSVC */ } @@ -508,17 +508,17 @@ pdf_parse_ind_obj(pdf_document *xref, tok = pdf_lex(file, buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "expected object number"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected object number"); num = buf->i; tok = pdf_lex(file, buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "expected generation number (%d ? obj)", num); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected generation number (%d ? obj)", num); gen = buf->i; tok = pdf_lex(file, buf); if (tok != PDF_TOK_OBJ) - fz_throw(ctx, "expected 'obj' keyword (%d %d ?)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected 'obj' keyword (%d %d ?)", num, gen); tok = pdf_lex(file, buf); @@ -558,14 +558,14 @@ pdf_parse_ind_obj(pdf_document *xref, break; } } - fz_throw(ctx, "expected 'R' keyword (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected 'R' keyword (%d %d R)", num, gen); case PDF_TOK_ENDOBJ: obj = pdf_new_null(ctx); goto skip; default: - fz_throw(ctx, "syntax error in object (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in object (%d %d R)", num, gen); } fz_try(ctx) @@ -575,7 +575,7 @@ pdf_parse_ind_obj(pdf_document *xref, fz_catch(ctx) { pdf_drop_obj(obj); - fz_throw(ctx, "cannot parse indirect object (%d %d R)", num, gen); + fz_rethrow_message(ctx, "cannot parse indirect object (%d %d R)", num, gen); } skip: |