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 /cbz | |
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 'cbz')
-rw-r--r-- | cbz/mucbz.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/cbz/mucbz.c b/cbz/mucbz.c index c61304d2..bbc8a5fe 100644 --- a/cbz/mucbz.c +++ b/cbz/mucbz.c @@ -85,7 +85,7 @@ cbz_read_zip_entry(cbz_document *doc, int offset, int *sizep) sig = getlong(doc->file); if (sig != ZIP_LOCAL_FILE_SIG) - fz_throw(ctx, "wrong zip local file signature (0x%x)", sig); + fz_throw(ctx, FZ_ERROR_GENERIC, "wrong zip local file signature (0x%x)", sig); (void) getshort(doc->file); /* version */ (void) getshort(doc->file); /* general */ @@ -135,15 +135,15 @@ cbz_read_zip_entry(cbz_document *doc, int offset, int *sizep) { code = inflateInit2(&stream, -15); if (code != Z_OK) - fz_throw(ctx, "zlib inflateInit2 error: %s", stream.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib inflateInit2 error: %s", stream.msg); code = inflate(&stream, Z_FINISH); if (code != Z_STREAM_END) { inflateEnd(&stream); - fz_throw(ctx, "zlib inflate error: %s", stream.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib inflate error: %s", stream.msg); } code = inflateEnd(&stream); if (code != Z_OK) - fz_throw(ctx, "zlib inflateEnd error: %s", stream.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib inflateEnd error: %s", stream.msg); } fz_always(ctx) { @@ -159,7 +159,7 @@ cbz_read_zip_entry(cbz_document *doc, int offset, int *sizep) return udata; } - fz_throw(ctx, "unknown zip method: %d", method); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown zip method: %d", method); return NULL; /* not reached */ } @@ -184,7 +184,7 @@ cbz_read_zip_dir_imp(cbz_document *doc, int startoffset) sig = getlong(file); if (sig != ZIP_END_OF_CENTRAL_DIRECTORY_SIG) - fz_throw(ctx, "wrong zip end of central directory signature (0x%x)", sig); + fz_throw(ctx, FZ_ERROR_GENERIC, "wrong zip end of central directory signature (0x%x)", sig); (void) getshort(file); /* this disk */ (void) getshort(file); /* start disk */ @@ -204,7 +204,7 @@ cbz_read_zip_dir_imp(cbz_document *doc, int startoffset) sig = getlong(doc->file); if (sig != ZIP_CENTRAL_DIRECTORY_SIG) - fz_throw(doc->ctx, "wrong zip central directory signature (0x%x)", sig); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "wrong zip central directory signature (0x%x)", sig); (void) getshort(file); /* version made by */ (void) getshort(file); /* version to extract */ @@ -271,7 +271,7 @@ cbz_read_zip_dir(cbz_document *doc) back += sizeof buf - 4; } - fz_throw(doc->ctx, "cannot find end of central directory"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find end of central directory"); } cbz_document * @@ -309,13 +309,18 @@ cbz_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 = cbz_open_document_with_stream(ctx, file); - } fz_always(ctx) { + } + fz_always(ctx) + { fz_close(file); - } fz_catch(ctx) { + } + fz_catch(ctx) + { fz_rethrow(ctx); } |