6.4 Summary

The basic exception handling rules are as follows:

  1. All MuPDF functions except those that explicitly state otherwise, throw exceptions on errors, and must therefore be called from within a fz_try/fz_catch construct.
  2. A fz_try block must be paired with a fz_catch block, and optionally a fz_always block can appear between them.
  3. Never return from a fz_try block.
  4. A fz_try block will terminate when control reaches the end of the block, or when break is called.
  5. Any local variable that is changed within a fz_try block may lose its value if an exception occurs, unless protected by fz_var call.
  6. The contents of the fz_always block will always be executed (after the fz_try block and before the fz_catch block, if appropriate).
  7. If an exception is thrown during the fz_try block, control will jump to the fz_always block (if there is one) and then continue to the fz_catch block.