14.5. Exception throwing in delegates

When a delegate instance is invoked, and an unhandled exception occurs in one of the methods on the instance's invocation list, the remaining methods will not be invoked and the exception is thrown to the delegate instance's context (see Figure 14.4). The diagram shows the scenario whereby a delegate instance contains five methods in its invocation list. When this instance is invoked, Method1 and Method2 are invoked in turn. Let's assume that when Method3 is invoked, an unhandled exception occurs. As a result, Method4 and Method5 will not execute and the exception object is thrown to the delegate instance's context.

Figure 14.4. Method4 and Method5 will not execute if an exception occurs when Method3 is invoked. ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.