12. Error Handling and Avoidance

Errors happen. There’s no magic bullet that’ll help you to avoid all errors your code could possibly ever encounter. But you can, of course, try to program defensively and anticipatory so that typical errors are noticed early and avoided before they can harm you. And you can be prepared to handle those errors that can’t be avoided.

Many modern programming languages nowadays include facilities for structured exception handling and COMMON LISP is no exception (pun intended).1 But it is different from many other languages in that it

  1. generalizes exceptions through its hierarchy of conditions,
  2. doesn’t necessarily unwind the stack if an exception occurs, and
  3. offers restarts to programmatically continue “where the ...

Get Common Lisp Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.