liveBook · Manning

Asynchronous exception

As explained in Functional Design and Architecture: Examples in Haskell

An asynchronous exception is an exception delivered independently of the execution point of the thread or computation it interrupts.

An asynchronous exception is delivered independently of the execution point of the thread or computation it interrupts. In Haskell, one thread can cause an exception to occur in another thread, making control flow difficult to understand. section 13.1.1

Treat asynchronous exceptions as an architectural boundary problem:

  • Prohibit asynchronous exceptions in the framework and underlying libraries because they can interrupt logic unexpectedly and crash an otherwise innocent thread. section 13.1.3
  • Catch exceptions at interpreters and prevent external exceptions from leaking into business logic. section 13.1.3
  • Convert native exceptions into explicit error values such as Either, so application logic can handle them deliberately. section 13.1.3

File-system interpreter

A file-system operation can catch the native exception inside its interpreter, convert the result into an FSResult value, and pass that value onward. The business logic then receives a controlled success or error result instead of an asynchronous failure escaping from the external layer.

Figure 13.7 Total exceptions gatekeeping

Use the exception-gatekeeping diagram to trace how interpreters catch and convert failures before they reach business logic. section 13.1.3

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines cross-thread delivery and recommends prohibition plus interpreter-level gatekeeping, without detailing an asynchronous-exception handling procedure.
Examples
Uses Haskell threads, native file-system operations, explicit Either-based results, and interpreter exception conversion.
What it assumes
Assumes exceptions, threads, and layered application architecture while distinguishing asynchronous exceptions from synchronous ones.
What you can do after
Evaluate exception boundaries and design interpreters that keep unpredictable external failures out of business logic.
How it connects
Connects asynchronous exceptions to synchronous exceptions, error handling, interpreters, native libraries, business logic, and free monads.

Also explained in

Compare how 2 books explain asynchronous exception →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.