4.10 Exception handling
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Exception handling
          • catch/3
          • throw/1
          • catch_with_backtrace/3
          • Urgency of exceptions
          • Debugging and exceptions
          • The exception term
    • Packages
Availability:built-in
Sourcecatch_with_backtrace(:Goal, +Catcher, :Recover)
As catch/3, but if library library(prolog_stack) is loaded and an exception of the shape error(Format, Context) is raised Context is extended with a backtrace. To catch an error and print its message including a backtrace, use the following template:
:- use_module(library(prolog_stack)).

    ...,
    catch_with_backtrace(Goal, Error,
                         print_message(error, Error)),
    ...,

This is good practice for a catch-all wrapper around an application. See also main/0 from library library(main).