dcsimg
 

Submitted by: Srinath M S(srinath_ms@yahoo.com)

Monday Jul 30th 2018 by Srinath M S

Language: .NET, Expertise: Intermediate - Learn how to use the ExceptionDispatchInfo class to capture the entire exception with the stack trace and throw it later.

The ExceptionDispatchInfo class can be found in System.Runtime.ExceptionServices namespace and is used to capture an exception that occurs at a point, and it can be thrown later using the ExceotionDispatchInfo.Throw method.

See below for an example.

ExceptionDispatchInfo exceptionDispatchInfo = null;  
try 
{
     //code that throws error 
} 
catch (Exception ex) 
{     
     exceptionDispatchInfo = ExceptionDispatchInfo.Capture(ex); 
}

At a later point in time, you could use the Throw method to throw it, exceptionDispatchInfo.Throw();

Home
Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved