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 /image/muimage.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 'image/muimage.c')
-rw-r--r-- | image/muimage.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/image/muimage.c b/image/muimage.c index 890457ab..ed3280b2 100644 --- a/image/muimage.c +++ b/image/muimage.c @@ -54,13 +54,18 @@ image_open_document(fz_context *ctx, const char *filename) file = fz_open_file(ctx, filename); if (!file) - 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_try(ctx) { + fz_try(ctx) + { doc = image_open_document_with_stream(ctx, file); - } fz_always(ctx) { + } + fz_always(ctx) + { fz_close(file); - } fz_catch(ctx) { + } + fz_catch(ctx) + { fz_rethrow(ctx); } |