Of course, CL has a very nice system of conditions. One simple option is to wrap the do-http-request call in ignore-errors , which returns nil (and the condition as the second value) if an error condition was specified in the wrapped code. Then you can check nil .
If you want something more like Java exception handling, just use the handler-case and add the appropriate error clause (I don't have AllegroServe, but I suppose you get socket-error for the wrong URL - just change this part if I read incorrectly):
(handler-case (do-http-request …) (socket-error () …))
If you need a finally -like function, use unwind-protect :
(unwind-protect (handler-case (do-http-request …) (socket-error (condition) ; bind the signalled condition …) ; code to run when a socket-error was signalled (:no-error (value) ; bind the returned value …)) ; code to run when no condition was signalled …) ; cleanup code (finally)
You can even get more fancy and, for example, use handler-bind to process the condition stack up, causing a reboot somewhere on the stack without unwinding it. For example, if do-http-request granted a reboot to try again with a different URL, you can handle your error condition by causing a restart with a new URL to retry. I just mentioned this for the sake of completeness - this would be redundant for your use case, but the ability to resume (possibly costly) calculations can easily be a pretty handy feature.
source share