While interpreting expressions or statements, errors may be raised. In such cases, the default POD behaviour is to nevertheless generate a POD result, into which a comment containing an explanation about the error, together with the Python traceback, is produced at the place where the expression result or the document part being the target of a statement would have been generated.
The example below defines an expression using a variable named "A" that is not defined in the context.
Instead of containing the result of evaluating A+B, the result contains a comment giving an explanation about the error and the Python traceback, as shown below.
In the next example, we try to render a table if a condition is True, but evaluating the condition produces an error (name zzz is not defined).
The table is rendered but only contains a comment explaining what happened.
The following example illustrates errors produced while evaluating for statements.
The result is as follows.
The previous examples were all examples of runtime errors, ie, errors that were produced while rendering the template. Errors may also occur at parsing time, when POD reads the content of comments and conditional fields to analyse the Python-like expressions. In the example below, statements do not respect the POD syntax.
Complete error messages are present as comments.
Raising classical exceptions
I know some people are uncomfortable with errors being embedded as notes within ODT results. It is true that, with this system, is is not possible to automatically detect that an error occurred: a human being must consult the file to realize that it contains an error. On the other side, if the error is not that important, the result is nevertheless generated and may do the job, while the error is being corrected. It is up to you to decide what best fits your needs. If you want real exceptions to be raised, set parameter raiseOnError to True on the Renderer, as illustrated here:
Renderer('SimpleTest.odt', globals(), 'result.odt', raiseOnError=True)
Alert - When your POD template is an ODS template, raiseOnError is always forced to True. A technical problem prevents POD to dump notes with tracebacks into ODS results.