Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

fuzion/runtime/check_fault.fz


# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation.  If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
#  Tokiwa Software GmbH, Germany
#
#  Source code of Fuzion standard library feature check_fault
#
#  Author: Fridtjof Siebert (siebert@tokiwa.software)
#
# -----------------------------------------------------------------------

# check_fault -- effect that terminates a computation due to a failed
# condition in a check statement
#
public check_fault (
  # the handler this effect uses to fail
  p String -> void
  ) : eff.fallible p
is


  # install default check_fault handler
  type.install_default =>
    (fuzion.runtime.check_fault msg->
      fuzion.runtime.contract_fault.cause ("check", msg)).default


  # create an instance of `check_fault` with the given error handler.
  #
  public fixed redef type.new(h String -> void) fuzion.runtime.check_fault => fuzion.runtime.check_fault h


# check_fault with no argument returns check_fault.env, the currently installed
# runtime check_fault handler.
#
public check_fault check_fault =>
  check_fault.install_default
  check_fault.env


# cause a check fault with given msg argument, i.e., call check_fault.cause
# msg, i.e., use the current check_fault effect to fail with the given message.
#
public checkcondition_fault(msg String) void => check_fault.cause msg

last changed: 2026-03-05