10.07.2015 Views

Download - Multivac!

Download - Multivac!

Download - Multivac!

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

necessary. After fatal exceptions the PDF document cannot be used, and will be left inan incomplete and inconsistent state. Obviously, the appropriate action when an exceptionoccurs is application-specific.For C and C++ clients which do not catch exceptions, the default action upon exceptionsis to issue an appropriate message on the standard error channel, and exit on fatalerrors. The PDF output file will be left in an incomplete state! Since this may not be adequatefor a library routine, for serious PDFlib projects it is strongly advised to leveragePDFlib’s exception handling facilities. A user-defined catch clause may, for example,present the error message in a GUI dialog box, and take other measures instead of aborting.Volatile variables. Special care must be taken regarding variables that are used in boththe PDF_TRY( ) and the PDF_CATCH( ) blocks. Since the compiler doesn’t know about thecontrol transfer from one block to the other, it might produce inappropriate code (e.g.,register variable optimizations) in this situation. Fortunately, there is a simple rule toavoid these problems:Note Variables used in both the PDF_TRY( ) and PDF_CATCH( ) blocks should be declared volatile.Using the volatile keyword signals to the compiler that it must not apply (potentiallydangerous) optimizations to the variable.Nesting try/catch blocks and rethrowing exceptions. PDF_TRY( ) blocks may be nestedto an arbitrary depth. In the case of nested error handling, the inner catch block can activatethe outer catch block by re-throwing the exception:PDF_TRY(p) /* outer try block */{/* ... */PDF_TRY(p) /* inner try block */{/* ... */}PDF_CATCH(p) /* inner catch block */{/* error cleanup */PDF_RETHROW(p);}/* ... */}PDF_CATCH(p) /* outer catch block */{/* more error cleanup */PDF_delete(p);}The PDF_RETHROW( ) invocation in the inner error handler will transfer program executionto the first statement of the outer PDF_CATCH( ) block immediately.Prematurely exiting a try block. If a PDF_TRY( ) block is left – e.g., by means of a returnstatement –, thus bypassing the invocation of the corresponding PDF_CATCH( ) macro,the PDF_EXIT_TRY( ) macro must be used to inform the exception machinery. No other libraryfunction must be called between this macro and the end of the try block:28 Chapter 2: PDFlib Language Bindings

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!