Skip to content
Björn Lindqvist edited this page Aug 13, 2015 · 12 revisions

This page describes error handling in Factor. The errors can be divided into three groups, soft, hard and unrecoverable.

Soft Errors

A soft error is one that originates with a call to the throw word. You can trigger a soft error easily:

IN: scratchpad "hello" throw
hello

Type :help for debugging help.
IN: scratchpad 

Under the hood, this just calls the special-object ERROR-HANDLER-QUOT:

IN: scratchpad "hello" ERROR-HANDLER-QUOT special-object call
hello

Type :help for debugging help.
IN: scratchpad 

And under that quotations hood, it just sets three global dynamic variables and calls rethrow with the error:

IN: scratchpad "hello" rethrow
hello

Type :help for debugging help.

Hard Errors

Hard errors, in contrast to soft errors, are not produced by the VM but by the operating system. They can be created like this:

IN: scratchpad 0 <alien> 0 alien-unsigned-1
Memory protection fault at address 0

Type :help for debugging help.

The Catchstack

The catchstack can be seen as a stack of recover frames. Each recover block add another frames to the stack. Normally in the listener, there are three sets of frames:

IN: scratchpad catchstack* length .
3

But if you nest three recover blocks in each other, you add three more:

IN: scratchpad [ 
    [ [ catchstack* length ] [ ] recover ] [ ] recover 
] [ ] recover .
6