summaryrefslogtreecommitdiff
path: root/fitz/base_error.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-06-19 18:08:16 +0100
committerRobin Watts <robin.watts@artifex.com>2013-06-19 18:22:26 +0100
commit06417814d2fcea74e3f7128c77cef8cc43952a8a (patch)
tree22bf8b168644a56bb437b08299e8ffeac4d281e8 /fitz/base_error.c
parentce6dc95e477cbf58a2c5e4465d00f156a56fefe5 (diff)
downloadmupdf-06417814d2fcea74e3f7128c77cef8cc43952a8a.tar.xz
Exception handling fixes.
Various tweaks to ensure the exception handling works as expected when throwing error values. The key thing is not to reset the error value on a try, as this can cause problems when code calls trys in the always section.
Diffstat (limited to 'fitz/base_error.c')
-rw-r--r--fitz/base_error.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/fitz/base_error.c b/fitz/base_error.c
index f16dd4d0..50b3c5aa 100644
--- a/fitz/base_error.c
+++ b/fitz/base_error.c
@@ -89,7 +89,6 @@ int fz_push_try(fz_error_context *ex)
{
assert(ex);
ex->top++;
- ex->errcode = FZ_ERROR_NONE;
/* Normal case, get out of here quick */
if (ex->top < nelem(ex->stack)-1)
return 1; /* We exit here, and the setjmp sets the code to 0 */
@@ -107,15 +106,13 @@ int fz_push_try(fz_error_context *ex)
int fz_caught(fz_context *ctx)
{
- assert(ctx);
- assert(ctx->error);
+ assert(ctx && ctx->error && ctx->error->errcode >= FZ_ERROR_NONE);
return ctx->error->errcode;
}
const char *fz_caught_message(fz_context *ctx)
{
- assert(ctx);
- assert(ctx->error);
+ assert(ctx && ctx->error && ctx->error->errcode >= FZ_ERROR_NONE);
return ctx->error->message;
}
@@ -136,12 +133,16 @@ void fz_throw(fz_context *ctx, int code, const char *fmt, ...)
void fz_rethrow(fz_context *ctx)
{
+ assert(ctx && ctx->error && ctx->error->errcode >= FZ_ERROR_NONE);
throw(ctx->error);
}
void fz_rethrow_message(fz_context *ctx, const char *fmt, ...)
{
va_list args;
+
+ assert(ctx && ctx->error && ctx->error->errcode >= FZ_ERROR_NONE);
+
va_start(args, fmt);
vsnprintf(ctx->error->message, sizeof ctx->error->message, fmt, args);
va_end(args);