From 8a22a7a76be8d9b439ee73383edbdf9d554bf3eb Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 18 Jun 2013 20:14:40 +0100 Subject: 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. --- include/mupdf/fitz/context.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h index 5f36370a..5f5df366 100644 --- a/include/mupdf/fitz/context.h +++ b/include/mupdf/fitz/context.h @@ -34,6 +34,7 @@ struct fz_error_context_s int code; fz_jmp_buf buffer; } stack[256]; + int errcode; char message[256]; }; @@ -64,10 +65,19 @@ void fz_var_imp(void *); if (ctx->error->stack[ctx->error->top--].code > 1) int fz_push_try(fz_error_context *ex); -void fz_throw(fz_context *, const char *, ...) __printflike(2, 3) FZ_NORETURN; +void fz_throw(fz_context *, int errcode, const char *, ...) __printflike(3, 4) FZ_NORETURN; void fz_rethrow(fz_context *) FZ_NORETURN; +void fz_rethrow_message(fz_context *, const char *, ...) __printflike(2, 3) FZ_NORETURN; void fz_warn(fz_context *ctx, const char *fmt, ...) __printflike(2, 3); -const char *fz_caught(fz_context *ctx); +const char *fz_caught_message(fz_context *ctx); +int fz_caught(fz_context *ctx); + +enum +{ + FZ_ERROR_NONE = 0, + FZ_ERROR_GENERIC = 1, + FZ_ERROR_COUNT +}; /* fz_flush_warnings: Flush any repeated warnings. -- cgit v1.2.3