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_pixmap.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_pixmap.c')
-rw-r--r-- | fitz/res_pixmap.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index 4288d379..1d3d536f 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -30,7 +30,7 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h fz_pixmap *pix; if (w < 0 || h < 0) - fz_throw(ctx, "Illegal dimensions for pixmap %d %d", w, h); + fz_throw(ctx, FZ_ERROR_GENERIC, "Illegal dimensions for pixmap %d %d", w, h); pix = fz_malloc_struct(ctx, fz_pixmap); FZ_INIT_STORABLE(pix, 1, fz_free_pixmap_imp); @@ -60,7 +60,7 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h fz_try(ctx) { if (pix->w + pix->n - 1 > INT_MAX / pix->n) - fz_throw(ctx, "overly wide image"); + fz_throw(ctx, FZ_ERROR_GENERIC, "overly wide image"); pix->samples = fz_malloc_array(ctx, pix->h, pix->w * pix->n); } fz_catch(ctx) @@ -439,11 +439,11 @@ fz_write_pnm(fz_context *ctx, fz_pixmap *pixmap, char *filename) int len; if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4) - fz_throw(ctx, "pixmap must be grayscale or rgb to write as pnm"); + fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as pnm"); fp = fopen(filename, "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)); if (pixmap->n == 1 || pixmap->n == 2) fprintf(fp, "P5\n"); @@ -498,7 +498,7 @@ fz_write_pam(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) fp = fopen(filename, "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)); fprintf(fp, "P7\n"); fprintf(fp, "WIDTH %d\n", pixmap->w); @@ -565,7 +565,7 @@ fz_write_png(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) 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); @@ -609,7 +609,7 @@ fz_output_png(fz_output *out, const fz_pixmap *pixmap, int savealpha) fz_var(cdata); if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4) - fz_throw(ctx, "pixmap must be grayscale or rgb to write as png"); + fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as png"); sn = pixmap->n; dn = pixmap->n; @@ -662,7 +662,7 @@ fz_output_png(fz_output *out, const fz_pixmap *pixmap, int savealpha) { fz_free(ctx, udata); fz_free(ctx, cdata); - fz_throw(ctx, "cannot compress image data"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot compress image data"); } big32(head+0, pixmap->w); |