VSL - The control.exception Structure
# Copyright 2011 Petter Urkedal
#
# This file is part of the Viz Standard Library <http://www.vizlang.org/>.
#
# The Viz Standard Library (VSL) is free software: you can redistribute it
# and/or modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# The VSL 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 Lesser General Public License for
# more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with the VSL. If not, see <http://www.gnu.org/licenses/>.
# Z. Exceptions
open prelude.ubiquitous
open effect
# Z.1. Elementary Exceptions
#
# These are the exceptions related to elementary operations; other exceptions
# are defined in their respective library structures.
type arith_issue
inj overflow
inj undeflow
inj loss_of_precision
inj division_by_zero
inj denormalized
inj arith_exception : arith_issue → exception
type async_issue
inj stack_overflow
inj heap_overflow
inj thread_killed
inj user_interrupt
inj async_exception : async_issue → exception
# Z.2. Exception Handling
val catch : (exception → io α) → io α → io α
val mask : ((∀α. io α → io α) → io β) → io β
val bracket : io α → (α → io unit) → (α → io β) → io β
let catch be __builtin_catch
let mask be __builtin_mask
let bracket init finit thunk be mask that which!
at restore : ∀α. io α → io α
let x do init
let r upon e do finit x
raise e
do restore (thunk x)
do finit x
be r