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 /fitz/res_pcl.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 'fitz/res_pcl.c')
-rw-r--r-- | fitz/res_pcl.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/fitz/res_pcl.c b/fitz/res_pcl.c index d5b351d4..eae5dad2 100644 --- a/fitz/res_pcl.c +++ b/fitz/res_pcl.c @@ -178,7 +178,7 @@ void fz_pcl_preset(fz_context *ctx, fz_pcl_options *opts, const char *preset) else if (!strcmp(preset, "oce9050")) copy_opts(opts, &fz_pcl_options_oce9050); else - fz_throw(ctx, "Unknown preset '%s'", preset); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unknown preset '%s'", preset); } void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, int val) @@ -203,7 +203,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in opts->features = (opts->features & ~PCL_ANY_SPACING) | PCL5_SPACING; break; default: - fz_throw(ctx, "Unsupported PCL spacing %d (0-3 only)", val); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unsupported PCL spacing %d (0-3 only)", val); } } else if (!strcmp(option, "mode2")) @@ -213,7 +213,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_MODE_2_COMPRESSION; else - fz_throw(ctx, "Expected 0 or 1 for mode2 value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for mode2 value"); } else if (!strcmp(option, "mode3")) { @@ -222,7 +222,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_MODE_3_COMPRESSION; else - fz_throw(ctx, "Expected 0 or 1 for mode3 value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for mode3 value"); } else if (!strcmp(option, "eog_reset")) { @@ -231,7 +231,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_END_GRAPHICS_DOES_RESET; else - fz_throw(ctx, "Expected 0 or 1 for eog_reset value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for eog_reset value"); } else if (!strcmp(option, "has_duplex")) { @@ -240,7 +240,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_HAS_DUPLEX; else - fz_throw(ctx, "Expected 0 or 1 for has_duplex value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for has_duplex value"); } else if (!strcmp(option, "has_papersize")) { @@ -249,7 +249,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_CAN_SET_PAPER_SIZE; else - fz_throw(ctx, "Expected 0 or 1 for has_papersize value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for has_papersize value"); } else if (!strcmp(option, "has_copies")) { @@ -258,7 +258,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_CAN_PRINT_COPIES; else - fz_throw(ctx, "Expected 0 or 1 for has_papersize value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for has_papersize value"); } else if (!strcmp(option, "is_ljet4pjl")) { @@ -267,7 +267,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= HACK__IS_A_LJET4PJL; else - fz_throw(ctx, "Expected 0 or 1 for is_ljet4pjl value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for is_ljet4pjl value"); } else if (!strcmp(option, "is_oce9050")) { @@ -276,10 +276,10 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= HACK__IS_A_OCE9050; else - fz_throw(ctx, "Expected 0 or 1 for is_oce9050 value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for is_oce9050 value"); } else - fz_throw(ctx, "Unknown pcl option '%s'", option); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unknown pcl option '%s'", option); } static void @@ -409,7 +409,7 @@ fz_output_pcl(fz_output *out, const fz_pixmap *pixmap, fz_pcl_options *pcl) ctx = out->ctx; if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4) - fz_throw(ctx, "pixmap must be grayscale or rgb to write as pcl"); + fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as pcl"); pcl_header(out, pcl, 1, pixmap->xres); @@ -804,7 +804,7 @@ fz_write_pcl(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, fz_ fp = fopen(filename, append ? "ab" : "wb"); if (!fp) { - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); } fz_var(out); @@ -834,7 +834,7 @@ fz_write_pcl_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int appe fp = fopen(filename, append ? "ab" : "wb"); if (!fp) { - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); } fz_var(out); |