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 8615723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:26:58+00:00 2026-06-12T05:26:58+00:00

Common Lisp allows exception handling through conditions and restarts . In rough terms, when

  • 0

Common Lisp allows exception handling through conditions and restarts. In rough terms, when a function throws an exception, the “catcher” can decide how/whether the “thrower” should proceed. Does Prolog offer a similar system? If not, could one be built on top of existing predicates for walking and examining the call stack?

  • 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-12T05:27:00+00:00Added an answer on June 12, 2026 at 5:27 am

    The ISO/IEC standard of Prolog provides only a very rudimentary exception and error handling mechanism which is – more or less – comparable to what Java offers and far away from Common Lisp’s rich mechanism, but there are still some points worth noting. In particular, beside the actual signalling and handling mechanism, many systems provide a mechanism similar to unwind-protect. That is, a way to ensure that a goal will be executed, even in the presence of otherwise unhandled signals.

    ISO throw/1, catch/3

    An exception is raised/thrown with throw(Term). First a copy of Term is created with copy_term/2 lets call it Termcopy and then this new copy is used to search for a corresponding catch(Goal, Pattern, Handler) whose second argument unifies with Termcopy. When Handler is executed, all unifications caused by Goal are undone. So there is no way for the Handler to access the substitutions present when throw/1 is executed. And there is no way to continue at the place where the throw/1 was executed.

    Errors of built-in predicates are signaled by executing throw(error(Error_term, Imp_def)) where Error_term corresponds to one of ISO’s error classes and Imp_def may provide implementation defined extra information (like source file, line number etc).

    There are many cases where handling an error locally would be of great benefit but it is deemed by many implementors to be too complex to implement.

    The additional effort to make a Prolog processor handle each and every error locally is quite considerable and is much larger than in Common Lisp or other programming languages. This is due to the very nature of unification in Prolog. The local handling of an error would require to undo unifications performed during the execution of the built-in: An implementor has thus two possibilities to implement this:

    • create a “choice point” at the time of invoking a built-in predicate, this would incur a lot of additional overhead, both for creating this choice point and for “trailing” subsequent bindings
    • go through each and every built-in predicate manually and decide on a case-by-case basis how to handle errors — while this is the most efficient in terms of runtime overheads, this is also the most costly and error-prone approach

    Similar complexities are caused by exploiting WAM registers within built-ins. Again, one has the choice between a slow system or one with significant implementation overhead.

    exception_handler/3

    Many systems, however, provide internally better mechanisms, but few offer them consistently to the programmer. IF/Prolog provides exception_handler/3 which has the same arguments as catch/3 but handles the error or exception locally:

    [user] ?- catch((arg(a,f(1),_); Z=ok), error(type_error(_,_),_), fail).
    
    no
    
    [user] ?- exception_handler((arg(a,f(1),_); Z=ok), error(type_error(_,_),_), fail).
    
    Z       = ok
    
    yes
    

    setup_call_cleanup/3

    This built-in offered by quite a few systems. It is very similar to unwind-protect but requires some additional complexity due to Prolog’s backtracking mechanism. See its current definition.


    All these mechanisms need to be provided by the system implementor, they cannot be built on top of ISO Prolog.

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

Sidebar

Related Questions

In common lisp, we can use the remove function. It seems there is no
In common lisp, the function (trace name) can be used to see output about
Is there any persistence solution for Common Lisp, such as Elephant, that allows function
I installed ltk to Steel Bank Common Lisp with asdf-install, but I can't even
In Common Lisp you use the (null x) function to check for empty lists
In Common LISP I can do: (setf a1 'a) (setf 1a 'b) In clojure
The Common Lisp HyperSpec says in the funcall entry that (funcall function arg1 arg2
In Common Lisp I can conditionally exclude or include code for different implementations like
In common lisp I can do this: src-> (defmacro macro-hello () `hello) (eval '(macro-hello))
I'm writing a program in Common Lisp in which I need a function with

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.