The Artima Developer Community
Sponsored Link

Python Buzz Forum
Common Lisp error handling example

0 replies.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a flat view of this topic  Flat View
Previous Topic   Next Topic
Threaded View: This topic has 0 replies on 1 page
Martin Skou

Posts: 20
Nickname: martinskou
Registered: Jul, 2007

Martin Skou is a developer in Infoserv
Common Lisp error handling example Posted: Aug 10, 2012 7:14 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Martin Skou.
Original Post: Common Lisp error handling example
Feed Title: Python Fanatic
Feed URL: http://blog.1x.dk/feeds/posts/default
Feed Description: On Python web development.
Latest Python Buzz Posts
Latest Python Buzz Posts by Martin Skou
Latest Posts From Python Fanatic

; Error  handling example.

(define-condition some-error (error)
((what :initarg :what :initform "something" :reader what))
(:report (lambda (condition stream)
(format stream "Agh! ~@(~A~) error." (what condition))))
(:documentation "Some-error condition."))

(defun ignore-some-error1 ()
" Restart function "
(print "some error 1")
T)

(defun function-with-error ()
" Test function which generate an error. Called directly this will start the debugger/repl. "
(restart-case (error 'some-error :what "test")
(use-value (value) value) ; first restart function
(ignore-some-error1 () (ignore-some-error1)))) ; second restart function

(defun higher-function ()
" This funtion calls a function which contains an error, but invokes the desired restart.
Other higher-functions could select different restart or none at all, so the behaviour of
the function-with-error under error conditions is controlled on the higher-functions level. "
(handler-bind ((some-error
#'(lambda (c)
(invoke-restart 'ignore-some-error1))))
(function-with-error )))

Read: Common Lisp error handling example


Topic: The Structure Query Collection Previous Topic   Next Topic Topic: Starting on Lisp

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use