A.17 library(exceptions): Exception classification
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(exceptions): Exception classification
          • catch/4
          • exception/2
          • error_term/2
          • exception_term/2
          • exception_type/2
    • Packages
Availability::- use_module(library(exceptions)).(can be autoloaded)
Sourcecatch(:Goal, +ExceptionType, ?Ball, :Recover)
As catch/3, only catching exceptions for which exception(ErrorType,Ball) is true. See error/2. For example, the code below properly informs the user some file could not be processed due do some issue with File, while propagating on all other reasons while process/1 could not be executed.
    catch(process(File), file_error, Ball,
          file_not_processed(File, Ball))

file_not_processed(File, Ball) :-
    message_to_string(Ball, Msg),
    format(user_error, 'Could not process ~p: ~s', [File, Msg]).