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. --- fitz/filt_faxd.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'fitz/filt_faxd.c') diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c index fab66f1a..8ac98f42 100644 --- a/fitz/filt_faxd.c +++ b/fitz/filt_faxd.c @@ -401,13 +401,13 @@ dec1d(fz_context *ctx, fz_faxd *fax) code = get_code(fax, cf_white_decode, cfd_white_initial_bits); if (code == UNCOMPRESSED) - fz_throw(ctx, "uncompressed data in faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "uncompressed data in faxd"); if (code < 0) - fz_throw(ctx, "negative code in 1d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "negative code in 1d faxd"); if (fax->a + code > fax->columns) - fz_throw(ctx, "overflow in 1d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "overflow in 1d faxd"); if (fax->c) setbits(fax->dst, fax->a, fax->a + code); @@ -440,13 +440,13 @@ dec2d(fz_context *ctx, fz_faxd *fax) code = get_code(fax, cf_white_decode, cfd_white_initial_bits); if (code == UNCOMPRESSED) - fz_throw(ctx, "uncompressed data in faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "uncompressed data in faxd"); if (code < 0) - fz_throw(ctx, "negative code in 2d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "negative code in 2d faxd"); if (fax->a + code > fax->columns) - fz_throw(ctx, "overflow in 2d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "overflow in 2d faxd"); if (fax->c) setbits(fax->dst, fax->a, fax->a + code); @@ -539,13 +539,13 @@ dec2d(fz_context *ctx, fz_faxd *fax) break; case UNCOMPRESSED: - fz_throw(ctx, "uncompressed data in faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "uncompressed data in faxd"); case ERROR: - fz_throw(ctx, "invalid code in 2d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid code in 2d faxd"); default: - fz_throw(ctx, "invalid code in 2d faxd (%d)", code); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid code in 2d faxd (%d)", code); } } -- cgit v1.2.3