C# › Exception Handling
How does exception handling interact with async/await, and how are exceptions from an async Task propagated to the awaiting caller?
AdvancedAnswer
An exception thrown inside an async method is captured and stored WITHIN the returned Task object (rather than thrown immediately at the call site); it's only actually re-thrown when the caller AWAITS that Task — this is why unobserved (never-awaited) Task exceptions can silently vanish, and why try/catch around an 'await' correctly catches exceptions from the awaited operation.
async Task<int> RiskyOperationAsync() {
throw new InvalidOperationException("Failed");
}
try {
int result = await RiskyOperationAsync(); // exception surfaces HERE, at the await
} catch (InvalidOperationException ex) {
Console.WriteLine($"Caught: {ex.Message}");
}Real-world example Understanding why an exception from a 'fire-and-forget' unwaited Task might silently disappear instead of crashing anything visibly.