Search⌘ K

Exceptions and Fibers

Explore the mechanics of exceptions and fibers in the D programming language. Understand how stack unwinding works during thrown exceptions and how fibers manage their own call stacks. Learn to use Fiber.yieldAndThrow to handle errors without terminating fibers, enabling efficient and resilient concurrency management.

We'll cover the following...

Earlier, you saw how “an exception object that is thrown from a lower level function is transferred to the higher level functions one level at a time.” We also discussed how an uncaught exception “causes the program to finally exit the main() function.” The described behavior of the exception mechanism can also be achieved by the call stack.

Stack unwinding

Continuing with the first example in this chapter, if an exception is thrown ...