O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Simple Example

To see how error-kit handles exceptions, we’ll create a simple application and perpetrate some errors. Let’s write an app that parses log file entries. Our log file entries will look like this:

 2008-10-05 12:14:00 WARN Some warning message here...

In this imperfect world, it is inevitable that some miscreant will pass bad data to the log file parser. To deal with this, we will define an error:

 (use 'clojure.contrib.error-kit)
 (deferror malformed-log-entry [] [msg]
  {:msg msg
  :unhandled (throw-msg IllegalArgumentException)})

The error takes a single argument, a msg describing the problem. The :unhandled value defers to a normal Clojure (Java) exception in the event that a caller chooses not to handle the error. (The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required