On this page:
try
throw
error
Exn
Exn.Fail
Exn.Fail.Contract
Exn.Fail.Contract.Arity
Exn.Fail.Contract.Divide  By  Zero
Exn.Fail.Contract.Non  Fixnum  Result
Exn.Fail.Contract.Continuation
Exn.Fail.Contract.Variable
Exn.Fail.Syntax
Exn.Fail.Syntax.Unbound
Exn.Fail.Syntax.Missing  Module
Exn.Fail.Read
Exn.Fail.Read.EOF
Exn.Fail.Read.Non  Char
Exn.Fail.Filesystem
Exn.Fail.Filesystem.Exists
Exn.Fail.Filesystem.Version
Exn.Fail.Filesystem.Errno
Exn.Fail.Filesystem.Missing  Module
Exn.Fail.Network
Exn.Fail.Network.Errno
Exn.Fail.Out  Of  Memory
Exn.Fail.Unsupported
Exn.Fail.User
Exn.Break
Exn.Break.Hang  Up
Exn.Break.Terminate
8.12

6.18 Exceptions🔗ℹ

expression

try:

  maybe_initially

  body

  ...

  maybe_catch

  maybe_finally

 

maybe_initially

 = 

~initially: body; ...

 | 

~initially expr

 | 

ϵ

 

maybe_catch

 = 

~catch bind: body; ...

 | 

~catch

| bind: body; ...

| ...

 | 

ϵ

 

maybe_finally

 = 

~finally: body; ...

 | 

~finally expr

 | 

ϵ

Returns the value of the body sequence, but runs the body or expression of an ~initially clause when entry the try body (whether normally or by a continuation jump) and the body or expression of a ~finally clause when leaving the try body (whether normally or by a continuation jump, including exception throws).

If an excepotion is thrown during the the body sequence, the control escapes to the context of the try body sequence (i.e., “inside” the ~initially and ~finally guards) and the ~catch cases are tried in order. When a ~catch binding matches, then the result of the try form is the body of the ~catch clause. If no ~catch clause matches, the exception is re-thrown. Breaks are disabled while attempting to match a ~catch clause or evaluating its body.

The last body form of try are not in tail position is any of ~initially, ~catch, or ~finally is present. If none are present, the try form is the same as begin.

> try:

    ~initially: println("in")

    "ok"

    ~finally: println("out")

in

out

"ok"

> try:

    ~initially: println("in")

    1/0

    ~finally: println("out")

in

out

/: division by zero

> try:

    1/0

    ~catch exn :: Exn.Fail.Contract.DivideByZero:

      "handled"

"handled"

> try:

    ~initially: println("in")

    1/0

    ~catch _:

      println("ignoring all exceptions!")

      0

    ~finally: println("out")

in

ignoring all exceptions!

out

0

> def k:

    Continuation.prompt:

      try:

        ~initially: println("in")

        Continuation.capture k: k

        ~finally: println("out")

in

out

> k("again")

in

out

"again"

expression

throw expr

Throws the value of expr as an exception. Any value can be thrown, but typically thrown values are instances of a subclass of Exn.

function

fun error(message :: ReadableString)

  :: None

 

function

fun error(

  who :: maybe(ReadableString || Symbol || Identifier || Operator),

  message :: ReadableString

) :: None

Throws the Exn.Fail exception with message as the message and Continuation.Marks.current() as the continuation marks. If who is not #false, it is added to the beginning of the message, and a :  separator is added in between.

class

class Exn(message :: ReadableString, marks :: Continuation.Marks)

 

class

class Exn.Fail():

  extends Exn

 

class

class Exn.Fail.Contract():

  extends Exn.Fail

 

class

class Exn.Fail.Contract.Arity():

  extends Exn.Fail.Contract

 

class

class Exn.Fail.Contract.DivideByZero():

  extends Exn.Fail.Contract

 

class

class Exn.Fail.Contract.NonFixnumResult():

  extends Exn.Fail.Contract

 

class

class Exn.Fail.Contract.Continuation():

  extends Exn.Fail.Contract

 

class

class Exn.Fail.Contract.Variable(id :: Symbol):

  extends Exn.Fail.Contract

 

class

class Exn.Fail.Syntax(exprs :: PairList.of(Syntax)):

  extends Exn.Fail

 

class

class Exn.Fail.Syntax.Unbound():

  extends Exn.Fail.Syntax

 

class

class Exn.Fail.Syntax.MissingModule(path):

  extends Exn.Fail.Syntax

 

class

class Exn.Fail.Read(srclocs :: PairList.of(Srcloc)):

  extends Exn.Fail

 

class

class Exn.Fail.Read.EOF():

  extends Exn.Fail.Read

 

class

class Exn.Fail.Read.NonChar():

  extends Exn.Fail.Read

 

class

class Exn.Fail.Filesystem():

  extends Exn.Fail

 

class

class Exn.Fail.Filesystem.Exists():

  extends Exn.Fail.Filesystem

 

class

class Exn.Fail.Filesystem.Version():

  extends Exn.Fail.Filesystem

 

class

class Exn.Fail.Filesystem.Errno(errno :: Pair.of(Symbol, Int)):

  extends Exn.Fail.Filesystem

 

class

class Exn.Fail.Filesystem.MissingModule(path):

  extends Exn.Fail.Filesystem

 

class

class Exn.Fail.Network():

  extends Exn.Fail

 

class

class Exn.Fail.Network():

  extends Exn.Fail.Network

 

class

class Exn.Fail.Network.Errno(errno :: Pair.of(Symbol, Int)):

  extends Exn.Fail.Network

 

class

class Exn.Fail.OutOfMemory():

  extends Exn.Fail

 

class

class Exn.Fail.Unsupported():

  extends Exn.Fail

 

class

class Exn.Fail.User():

  extends Exn.Fail

 

class

class Exn.Break(continuation :: Continuation):

  extends Exn

 

class

class Exn.Break.HangUp():

  extends Exn.Break

 

class

class Exn.Break.Terminate():

  extends Exn.Break

Primitive exceptions.