Method DisposeWhileHandlingException
DisposeWhileHandlingException(Exception, IDisposable[])
Disposes all given IDisposable
s, suppressing all thrown exceptions. Some of the IDisposable
s
may be null
, they are ignored. After everything is disposed, method either throws priorException
,
if one is supplied, or the first of suppressed exceptions, or completes normally.
Sample usage:
IDisposable resource1 = null, resource2 = null, resource3 = null;
ExpectedException priorE = null;
try
{
resource1 = ...; resource2 = ...; resource3 = ...; // Acquisition may throw ExpectedException
..do..stuff.. // May throw ExpectedException
}
catch (ExpectedException e)
{
priorE = e;
}
finally
{
IOUtils.DisposeWhileHandlingException(priorE, resource1, resource2, resource3);
}
Declaration
public static void DisposeWhileHandlingException(Exception priorException, params IDisposable[] objects)
Parameters
Type | Name | Description |
---|---|---|
Exception | priorException |
|
IDisposable[] | objects | Objects to call |
DisposeWhileHandlingException(Exception, IEnumerable<IDisposable>)
Disposes all given
Declaration
public static void DisposeWhileHandlingException(Exception priorException, IEnumerable<IDisposable> objects)
Parameters
Type | Name | Description |
---|---|---|
Exception | priorException | |
IEnumerable<IDisposable> | objects |
See Also
DisposeWhileHandlingException(IDisposable[])
Disposes all given null
, they are ignored.
Declaration
public static void DisposeWhileHandlingException(params IDisposable[] objects)
Parameters
Type | Name | Description |
---|---|---|
IDisposable[] | objects | Objects to call |
DisposeWhileHandlingException(IEnumerable<IDisposable>)
Disposes all given
Declaration
public static void DisposeWhileHandlingException(IEnumerable<IDisposable> objects)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IDisposable> | objects |