Skip to content
BANG

6. Handling an effect

Teaches: with, catching raise

raise performs bang's built-in error effect; handle catches it and returns the raised value directly, short-circuiting whatever computation came after the raise. This is the same handle/with shape you'll use for effects you declare yourself, next.

handle (let z = raise 7 in 99)

Expected output (bang run stdout):

7

Run it yourself:

curl -fsSL https://raw.githubusercontent.com/phibkro/bang/main/tools/install.sh | sh
bang run examples/handle/main.bang

← 5. State as a library · 7. Declare your own effect →