• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
          • Saving-event-data
          • Trans-eval
          • System-utilities-non-built-in
            • Pseudo-event-formp
            • Pseudo-event-form-listp
            • Directed-untranslate
            • Irrelevant-formals-info
            • Numbered-names
            • Context-message-pair
            • Prove$
            • Minimize-ruler-extenders
            • Paired-names
            • Orelse
            • Fresh-name-in-world-with-$s
            • Encapsulate-report-errors
            • On-failure
              • Chk-irrelevant-formals-ok
              • Named-formulas
              • Pseudo-event-landmarkp
              • All-program-fns
              • All-logic-fns
              • Trans-eval-error-triple
              • Trans-eval-state
              • Pseudo-tests-and-callsp
              • User-interface
              • Pseudo-command-landmarkp
              • Pseudo-tests-and-calls-listp
              • Pseudo-command-formp
              • Orelse*
              • Identity-macro
            • Get-event-data
            • Untranslate
            • Constraint-info
          • Stobj
          • State
          • Mutual-recursion
          • Memoize
          • Mbe
          • Io
          • Defpkg
          • Apply$
          • Loop$
          • Programming-with-state
          • Arrays
          • Characters
          • Time$
          • Defconst
          • Fast-alists
          • Defmacro
          • Loop$-primer
          • Evaluation
          • Guard
          • Equality-variants
          • Compilation
          • Hons
          • ACL2-built-ins
          • Developers-guide
          • System-attachments
          • Advanced-features
          • Set-check-invariant-risk
          • Numbers
          • Efficiency
          • Irrelevant-formals
          • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
          • Redefining-programs
          • Lists
          • Invariant-risk
          • Errors
          • Defabbrev
          • Conses
          • Alists
          • Set-register-invariant-risk
          • Strings
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Oracle-eval
          • Defmacro-untouchable
          • <<
          • Primitive
          • Revert-world
          • Unmemoize
          • Set-duplicate-keys-action
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Fake-oracle-eval
          • Defopen
          • Sleep
        • Operational-semantics
        • Real
        • Start-here
        • Miscellaneous
        • Output-controls
        • Bdd
        • Macros
        • Installation
        • Mailing-lists
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • System-utilities-non-built-in

    On-failure

    Run an event, printing a custom error message if it fails.

    General Form:
    
    (on-failure event
                :ctx ctx ; default "event processing"
                :erp erp ; default t
                :val val ; default nil
                :msg msg ; default nil
                )

    where event is an embedded-event-form, and the other arguments are passed to fail-event as explained below. Thus, none of the arguments is evaluated. The General Form above expands to the following.

    (ORELSE EVENT
            (FAIL-EVENT CTX ERP VAL MSG))

    Thus, first event is evaluated — see orelse — and either it succeeds or else the indicated error occurs — see fail-event.

    Consider the following example.

    (on-failure (defund f (x) x)
                :ctx (defund . f) ; see :doc ctx
                :erp t   ; see :doc er-soft+
                :val nil ; see :doc er-soft+
                :msg ("Failed:~|~%~x0" (#\0 . (defun f (x) x))))

    If f is not already defined, then this is essentially equivalent to (defund f (x) x). But if f currently has a conflicting definition, then the event will fail and the final error message, unless error output is inhibited (see set-inhibit-output-lst), will be the following.

    ACL2 Error in (DEFUND F ...):  Failed:
    
    (DEFUN F (X) X)

    For another example of the use of on-failure, which uses the macro msg to construct a msgp, see the definition of function report-event-when-error-fn in community-book books/kestrel/utilities/orelse.lisp.