Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

AggregateException::Handle Method (Func<Exception^, Boolean>^)

 

Invokes a handler on each Exception contained by this AggregateException.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public:
void Handle(
	Func<Exception^, bool>^ predicate
)

Parameters

predicate
Type: System::Func<Exception^, Boolean>^

The predicate to execute for each exception. The predicate accepts as an argument the Exception to be processed and returns a Boolean to indicate whether the exception was handled.

Exception Condition
ArgumentNullException

The predicate argument is null.

AggregateException

An exception contained by this AggregateException was not handled.

Each invocation of the predicate returns true or false to indicate whether the Exception was handled. After all invocations, if any exceptions went unhandled, all unhandled exceptions will be put into a new AggregateException which will be thrown. Otherwise, the Handle method simply returns. If any invocations of the predicate throws an exception, it will halt the processing of any more exceptions and immediately propagate the thrown exception as-is.

Ordinarily, an exception handler that catches an AggregateException exception uses a foreach loop (in C#) or For Each loop (in Visual Basic) to handle each exception in its InnerExceptions collection. Instead, the following example uses the Handle method to handle each exception, and only re-throws exceptions that are not CustomException instances.

No code example is currently available or this language may not be supported.

The following is a more complete example that uses the Handle method to provide special handling for an UnauthorizedAccessException when enumerating files.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 5.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft