Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8934495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:48:04+00:00 2026-06-15T09:48:04+00:00

What I’m trying to do: I want the functionality of simple-error in another error.

  • 0

What I’m trying to do:
I want the functionality of simple-error in another error. I want this for these reasons:

  • to be able to handle it in a separate clause of handler-case.

  • to avoid specifying the message string over and over again…

  • to have debugger invoked when the error occurs.

I’m sort of puzzled this doesn’t happen naturally by default, never paid enough attention to this issue, but this is apparently how it functions… What I am able to do is to signal an error, which I can later handle with handler-case or handler-bind, but this is bad, because I don’t always remember whether the function throws or not, and when it does throw, but I forget to handle it, the function just returns early, as if nothing happened. But if I resume to using simple-error, then my code starts looking like:

...
(signal "Container ~S has no key ~S~&" :container foo :key bar)
...
(signal "Container ~S has no key ~S~&" :container foo :key baz)
...

And so on, all over the place :/ Of course I can dedicate a variable for saving the message text and maybe have a macro to make it shorter, but this doesn’t help really, because it only hides the actual clutter instead of solving the problem.

What I could do so far:

(define-condition missing-key (condition)
  ((key :initarg :key
        :accessor key-of)
   (container :initarg :container
              :accessor container-of))
  (:documentation
   "An error rised when a KEY is not in the CONTAINER"
   :report
   #'(lambda (condition stream)
       (unless *print-escape*
         (format stream "~&Container ~S has no key ~S"
                 (container-of condition)
                 (key-of condition))))))

(handler-bind
    ((missing-key
      #'(lambda (condition)
          (invoke-debugger condition))))
  (signal 'missing-key :key 'foo :container 'bar))

What happens, however is that reporting function never gets called… when the error is signalled, instead it prints a generic message Condition MISSING-KEY was signalled.

EDIT:

Thanks to sds answer, this is what I have now:

(define-condition missing-key (error)
  ((key :initarg :key
        :accessor key-of)
   (container :initarg :container
              :accessor container-of))
  (:documentation
   "An error rised when a KEY is not in the CONTAINER")
  (:report
   (lambda (condition stream)
     (format stream "Container ~S has no key ~S"
             (container-of condition)
             (key-of condition)))))

(defmacro signal-missing-key (container key)
  `(let ((*break-on-signals*
          (cond
            ((null *break-on-signals*) 'missing-key)
            ((consp *break-on-signals*)
             (list 'or 'missing-key (cdr *break-on-signals*)))
            (t (list 'or *break-on-signals* 'missing-key)))))
     (signal 'missing-key :key ,container :container ,key)))

I could probably make it more generic by passing more arguments down to signal, but this does what I wanted to do initially, so, unless there is a better way to do the same thing, I’ll probably just use this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:48:05+00:00Added an answer on June 15, 2026 at 9:48 am

    You can use error or cerror with your own condition types, if you want the debugger to be invoked unless the conditions are handled otherwise. This also works for conditions that are not descendants of simple-error.

    If you want this behavior for signal, too, you can set the variable *break-on-signals* to the according type. For example, you could set it to t in order to invoke the debugger for every unhandled condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.