PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Error policies. When <strong>PDFlib</strong> detects an error condition, it will react according to one of<br />
several strategies which can be configured with the errorpolicy parameter. All functions<br />
which can return error codes also support an errorpolicy option. The following error policies<br />
are supported:<br />
> errorpolicy=legacy: this deprecated setting ensures behavior which is compatible to<br />
earlier versions of <strong>PDFlib</strong>, where exceptions and error return values are controlled by<br />
parameters and options such as fontwarning, imagewarning, etc. This is only recommended<br />
for applications which require source code compatibility with <strong>PDFlib</strong> 6. It<br />
should not be used for new applications. The legacy setting is the default error policy.<br />
> errorpolicy=return: when an error condition is detected, the respective function will<br />
return with a -1 error value regardless of any warning parameters or options. The application<br />
developer must check the return value to identify problems, and must react<br />
on the problem in whatever way is appropriate for the application. This is the<br />
recommended approach since it allows a unified approach to error handling.<br />
> errorpolicy=exception: an exception will be thrown when an error condition is detected.<br />
However, the output document will be unusable after an exception. This can be<br />
used for lazy programming without any error conditionals at the expense of sacrificing<br />
the output document even for problems which may be fixable by the application.<br />
The following code fragments demonstrate different strategies with respect to exception<br />
handling. The examples try to load a font which may or may not be available.<br />
If errorpolicy=return the return value must be checked for an error. If it indicates failure,<br />
the reason of the failure can be queried in order to properly deal with the situation:<br />
font = p.load_font("MyFontName", "unicode", "errorpolicy=return");<br />
if (font == -1)<br />
{<br />
/* font handle is invalid; find out what happened. */<br />
errmsg = p.get_errmsg());<br />
/* Try a different font or give up */<br />
...<br />
}<br />
/* font handle is valid; continue */<br />
If errorpolicy=exception the document must be abandoned if an error occurs:<br />
font = p.load_font("MyFontName", "unicode", "errorpolicy=exception");<br />
/* Unless an exception was thrown the font handle is valid;<br />
* if an exception occurred, the PDF output cannot be continued<br />
*/<br />
Cookbook A full code sample can be found in the Cookbook topic general/error_handling.<br />
Warnings. Some problem conditions can be detected by <strong>PDFlib</strong> internally, but do not<br />
justify interrupting the program flow by throwing an exception. While earlier versions<br />
of <strong>PDFlib</strong> supported the concept of non-fatal exceptions which can be disabled, <strong>PDFlib</strong> 7<br />
never throws an exception for non-fatal conditions. Instead, a description of the condition<br />
will be logged (if logging is enabled). Logging can be enabled as follows:<br />
p.set_parameter("logging", "filename=private.log");<br />
We recommend the following approach with respect to warnings:<br />
60 Chapter 3: Creating PDF Documents (Edition for <strong>COM</strong>, .<strong>NET</strong>, and REALbasic)