Skip to main content

Chapter 4: Exception handling and cancellation

In this chapter

  • How await handles exceptions
    • Beware of the fire-and-forget trap
  • The role of AggregateException
    • Task.WhenAll and multiple exceptions
  • Canceling tasks gracefully
    • Requesting cancellation
    • Listening for cancellation and passing the token through
    • Registering cancellation callbacks
    • A non-cancelable token
  • Implementing timeouts
    • Testable timeout logic with TimeProvider (.NET 8+)
  • Summary

This chapter is not available in the free preview. Purchase the book to read the complete edition now.

Buy this book