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/image_jpx.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/image_jpx.c')
-rw-r--r-- | fitz/image_jpx.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/fitz/image_jpx.c b/fitz/image_jpx.c index 43a4d2ef..cd41277d 100644 --- a/fitz/image_jpx.c +++ b/fitz/image_jpx.c @@ -88,7 +88,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs stream_block sb; if (size < 2) - fz_throw(ctx, "not enough data to determine image format"); + fz_throw(ctx, FZ_ERROR_GENERIC, "not enough data to determine image format"); /* Check for SOC marker -- if found we have a bare J2K stream */ if (data[0] == 0xFF && data[1] == 0x4F) @@ -106,7 +106,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs opj_set_error_handler(codec, fz_opj_error_callback, ctx); if (!opj_setup_decoder(codec, ¶ms)) { - fz_throw(ctx, "j2k decode failed"); + fz_throw(ctx, FZ_ERROR_GENERIC, "j2k decode failed"); } stream = opj_stream_default_create(OPJ_TRUE); @@ -125,7 +125,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs { opj_stream_destroy(stream); opj_destroy_codec(codec); - fz_throw(ctx, "Failed to read JPX header"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to read JPX header"); } if (!opj_decode(codec, stream, jpx)) @@ -133,7 +133,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs opj_stream_destroy(stream); opj_destroy_codec(codec); opj_image_destroy(jpx); - fz_throw(ctx, "Failed to decode JPX image"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to decode JPX image"); } opj_stream_destroy(stream); @@ -141,24 +141,24 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs /* jpx should never be NULL here, but check anyway */ if (!jpx) - fz_throw(ctx, "opj_decode failed"); + fz_throw(ctx, FZ_ERROR_GENERIC, "opj_decode failed"); for (k = 1; k < (int)jpx->numcomps; k++) { if (jpx->comps[k].w != jpx->comps[0].w) { opj_image_destroy(jpx); - fz_throw(ctx, "image components have different width"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image components have different width"); } if (jpx->comps[k].h != jpx->comps[0].h) { opj_image_destroy(jpx); - fz_throw(ctx, "image components have different height"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image components have different height"); } if (jpx->comps[k].prec != jpx->comps[0].prec) { opj_image_destroy(jpx); - fz_throw(ctx, "image components have different precision"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image components have different precision"); } } @@ -205,7 +205,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs fz_catch(ctx) { opj_image_destroy(jpx); - fz_throw(ctx, "out of memory"); + fz_rethrow_message(ctx, "out of memory loading jpx"); } p = img->samples; |