Advertisement
Advanced C#, Delegates, Events & Lambdas

What is the difference between multicast delegate invocation and exception handling?

Short answer

A multicast delegate invokes subscribers in order; if one throws, later subscribers are skipped and the exception propagates. Invoke manually via GetInvocationList to isolate failures.

Save C# mock interview
Advertisement
AModel answer
A multicast delegate invokes subscribers in order; if one throws, later subscribers are skipped and the exception propagates. Invoke manually via GetInvocationList to isolate failures.
foreach (var d in handler.GetInvocationList().Cast<Action>())
    try { d(); } catch (Exception ex) { Log(ex); }
Real-world example
Notifying many listeners where one failing listener must not block the rest.