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 /apps | |
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 'apps')
-rw-r--r-- | apps/jstest_main.c | 2 | ||||
-rw-r--r-- | apps/mudraw.c | 10 | ||||
-rw-r--r-- | apps/pdfapp.c | 2 | ||||
-rw-r--r-- | apps/pdfclean.c | 2 | ||||
-rw-r--r-- | apps/pdfextract.c | 14 | ||||
-rw-r--r-- | apps/pdfinfo.c | 6 | ||||
-rw-r--r-- | apps/pdfposter.c | 2 | ||||
-rw-r--r-- | apps/pdfshow.c | 12 |
8 files changed, 25 insertions, 25 deletions
diff --git a/apps/jstest_main.c b/apps/jstest_main.c index f01eabfc..2003ad55 100644 --- a/apps/jstest_main.c +++ b/apps/jstest_main.c @@ -326,7 +326,7 @@ main(int argc, char *argv[]) scriptname = argv[fz_optind++]; script = fopen(scriptname, "rb"); if (script == NULL) - fz_throw(ctx, "cannot open script: %s", scriptname); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open script: %s", scriptname); do { diff --git a/apps/mudraw.c b/apps/mudraw.c index 366cdb8a..57bd4be2 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -271,7 +271,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) } fz_catch(ctx) { - fz_throw(ctx, "cannot load page %d in file '%s'", pagenum, filename); + fz_rethrow_message(ctx, "cannot load page %d in file '%s'", pagenum, filename); } if (mujstest_file) @@ -396,7 +396,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) { fz_drop_display_list(ctx, list); fz_free_page(doc, page); - fz_throw(ctx, "cannot draw page %d in file '%s'", pagenum, filename); + fz_rethrow_message(ctx, "cannot draw page %d in file '%s'", pagenum, filename); } } @@ -485,7 +485,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) sprintf(buf, output, pagenum); file = fopen(buf, "wb"); if (file == NULL) - fz_throw(ctx, "cannot open file '%s': %s", buf, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", buf, strerror(errno)); out = fz_new_output_with_file(ctx, file); fz_bound_page(doc, page, &bounds); @@ -983,13 +983,13 @@ int main(int argc, char **argv) } fz_catch(ctx) { - fz_throw(ctx, "cannot open document: %s", filename); + fz_rethrow_message(ctx, "cannot open document: %s", filename); } if (fz_needs_password(doc)) { if (!fz_authenticate_password(doc, password)) - fz_throw(ctx, "cannot authenticate password: %s", filename); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", filename); if (mujstest_file) fprintf(mujstest_file, "PASSWORD %s\n", password); } diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 7371ea0c..e76c6c7c 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -178,7 +178,7 @@ void pdfapp_open(pdfapp_t *app, char *filename, int reload) { password = winpassword(app, filename); if (!password) - fz_throw(ctx, "Needs a password"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Needs a password"); okay = fz_authenticate_password(app->doc, password); if (!okay) pdfapp_warn(app, "Invalid password."); diff --git a/apps/pdfclean.c b/apps/pdfclean.c index 3c1e810e..c437b819 100644 --- a/apps/pdfclean.c +++ b/apps/pdfclean.c @@ -212,7 +212,7 @@ int pdfclean_main(int argc, char **argv) xref = pdf_open_document_no_run(ctx, infile); if (pdf_needs_password(xref)) if (!pdf_authenticate_password(xref, password)) - fz_throw(ctx, "cannot authenticate password: %s", infile); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", infile); /* Only retain the specified subset of the pages */ if (subset) diff --git a/apps/pdfextract.c b/apps/pdfextract.c index 78a61f14..6e8e4aec 100644 --- a/apps/pdfextract.c +++ b/apps/pdfextract.c @@ -120,7 +120,7 @@ static void savefont(pdf_obj *dict, int num) obj = pdf_dict_gets(obj, "Subtype"); if (obj && !pdf_is_name(obj)) - fz_throw(ctx, "Invalid font descriptor subtype"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Invalid font descriptor subtype"); subtype = pdf_to_name(obj); if (!strcmp(subtype, "Type1C")) @@ -130,7 +130,7 @@ static void savefont(pdf_obj *dict, int num) else if (!strcmp(subtype, "OpenType")) ext = "otf"; else - fz_throw(ctx, "Unhandled font type '%s'", subtype); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unhandled font type '%s'", subtype); } if (!stream) @@ -146,15 +146,15 @@ static void savefont(pdf_obj *dict, int num) f = fopen(name, "wb"); if (!f) - fz_throw(ctx, "Error creating font file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Error creating font file"); len = fz_buffer_storage(ctx, buf, &data); n = fwrite(data, 1, len, f); if (n < len) - fz_throw(ctx, "Error writing font file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Error writing font file"); if (fclose(f) < 0) - fz_throw(ctx, "Error closing font file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Error closing font file"); fz_drop_buffer(ctx, buf); } @@ -164,7 +164,7 @@ static void showobject(int num) pdf_obj *obj; if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); obj = pdf_load_object(doc, num, 0); @@ -207,7 +207,7 @@ int pdfextract_main(int argc, char **argv) doc = pdf_open_document_no_run(ctx, infile); if (pdf_needs_password(doc)) if (!pdf_authenticate_password(doc, password)) - fz_throw(ctx, "cannot authenticate password: %s", infile); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", infile); if (fz_optind == argc) { diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c index fa21431e..79743892 100644 --- a/apps/pdfinfo.c +++ b/apps/pdfinfo.c @@ -576,7 +576,7 @@ gatherresourceinfo(int page, pdf_obj *rsrc, int show) pageref = xref->page_refs[page-1]; if (!pageobj) - fz_throw(ctx, "cannot retrieve info from page %d", page); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot retrieve info from page %d", page); font = pdf_dict_gets(rsrc, "Font"); if (show & FONTS && font) @@ -644,7 +644,7 @@ gatherpageinfo(int page, int show) pageref = xref->page_refs[page-1]; if (!pageobj) - fz_throw(ctx, "cannot retrieve info from page %d", page); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot retrieve info from page %d", page); gatherdimensions(page, pageref, pageobj); @@ -1008,7 +1008,7 @@ int pdfinfo_main(int argc, char **argv) xref = pdf_open_document_no_run(ctx, filename); if (pdf_needs_password(xref)) if (!pdf_authenticate_password(xref, password)) - fz_throw(ctx, "cannot authenticate password: %s", filename); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", filename); pagecount = pdf_count_pages(xref); showglobalinfo(); diff --git a/apps/pdfposter.c b/apps/pdfposter.c index 050a497f..ed3a4bda 100644 --- a/apps/pdfposter.c +++ b/apps/pdfposter.c @@ -170,7 +170,7 @@ int pdfposter_main(int argc, char **argv) xref = pdf_open_document_no_run(ctx, infile); if (pdf_needs_password(xref)) if (!pdf_authenticate_password(xref, password)) - fz_throw(ctx, "cannot authenticate password: %s", infile); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", infile); /* Only retain the specified subset of the pages */ decimatepages(xref); diff --git a/apps/pdfshow.c b/apps/pdfshow.c index 586a2fc6..78e3fd08 100644 --- a/apps/pdfshow.c +++ b/apps/pdfshow.c @@ -22,7 +22,7 @@ static void usage(void) static void showtrailer(void) { if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); printf("trailer\n"); pdf_fprint_obj(stdout, pdf_trailer(doc), 0); printf("\n"); @@ -33,10 +33,10 @@ static void showencrypt(void) pdf_obj *encrypt; if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); encrypt = pdf_dict_gets(pdf_trailer(doc), "Encrypt"); if (!encrypt) - fz_throw(ctx, "document not encrypted"); + fz_throw(ctx, FZ_ERROR_GENERIC, "document not encrypted"); printf("encryption dictionary\n"); pdf_fprint_obj(stdout, pdf_resolve_indirect(encrypt), 0); printf("\n"); @@ -45,7 +45,7 @@ static void showencrypt(void) static void showxref(void) { if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); pdf_print_xref(doc); printf("\n"); } @@ -57,7 +57,7 @@ static void showpagetree(void) int i; if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); count = pdf_count_pages(doc); for (i = 0; i < count; i++) @@ -123,7 +123,7 @@ static void showobject(int num, int gen) pdf_obj *obj; if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); obj = pdf_load_object(doc, num, gen); |