
214
19
Handling Exceptions
This chapter explains how to handle exceptions that are raised by Acrobat core API methods. Acrobat core
API methods generally do not return error codes; instead, they raise exceptions when errors occur.
Exceptions are handled by exception handlers. It is recommended that you create your own exception
handlers to trap and handle exceptions.
This chapter contains the following information.
Creating exception handlers
Exception handlers typically perform object cleanup (such as releasing memory) when an exception
occurs. Your exception handler can either deal with the exception or pass it along to the next handler on
the exception handler stack.
You use the
DURING
,
HANDLER
, and
END_HANDLER
macros to define exception handlers. Application
logic that may raise an exception appears between the
DURING
and
HANDLER
macros. Application logic
that handles exceptions appears between the
HANDLER
and
END_HANDLER
macros.
If the method raises an exception, the handler code is executed; otherwise, it is not executed. When an
exception occurs, your handler can access the exception error code by using the
ERRORCODE
macro. The
value returned by the
ERRORCODE
macro does not change until another exception is raised. For
information about the
ERRORCODE
macro, see the
Acrobat and PDF Library API Reference
.
The following code example declares an error handler that is active during a call to the
AVDocOpenFromFile
method. If an exception occurs, an error message is displayed to the user. For
information about opening a PDF document by using the
AVDocOpenFromFile
method, see
“Opening
PDF documents” on page 72
.
Example 19.1
Creating an exception handler
DURING
AVDoc avd = AVDocOpenFromFile(asp, NULL, (char *)NULL);
HANDLER
AVAlertNote("Error opening file");
END_HANDLER
Note:
For code brevity, most of the code examples located within this guide do not include
DURING
,
HANDLER
, and
END_HANDLER
macros to handle exceptions. You should include these macros in
your own custom code.
Topic
Description
See
Creating exception handlers
Describes how to create exception handlers.
page 214
Returning a value from an
exception handler
Describes how to return a value from an exception
handler.
page 215
Raising exceptions
Describes how to raise exceptions.
page 215
Exception handling scenarios
Describes scenarios related to exception handling.
page 215