Nonlocal Exception

A nonlocal exception is one raised in a different execution context than where it will be handled — in uC++, raised at a specific target coroutine rather than in the current one.

Why?

Plain exceptions propagate up the call stack of the current execution. Coroutines each have their own stack, so a coroutine sometimes needs to signal an event to another coroutine — the target isn’t on the raiser’s stack at all. Nonlocal exceptions are the mechanism to do this.

Syntax

_Resume Exception() _At C;   // deliver Exception to coroutine C

The _At C clause names the target. Without it, _Resume is local (current coroutine).

Mechanism: proxy raise

_Resume _At does not immediately run the handler in C. It queues the exception for C:

  • The source delivers the nonlocal exception immediately, but
  • Propagation (handler lookup in C) only happens when C becomes active — i.e. when something calls C.resume() or otherwise transfers control into it.

Once C is active, the queued exception is raised locally inside C — so nonlocal resumption becomes local resumption at the point where C next runs.

Multiple pending exceptions

If several nonlocal exceptions accumulate before C runs, they are delivered in FIFO order, subject to which exceptions are currently enabled.