How to add our own details to Exception error messages?

Topics: Exception Handling Application Block
May 14, 2009 at 2:29 PM

 

 

 

 

 

 

 

 

 

 

I am using the below code sample to implement Exception Handling,It's working well but i want add some my own details to Exception Message.How can i do that?

Please help me.

<font size="2" color="#0000ff"><font size="2" color="#0000ff">

try

</font></font><font size="2" color="#0000ff">

 

</font>

{

<font size="2">

 

</font>

 

int  intOut = 0;<font size="2">

 

</font>

 

bool fs = int.TryParse("TestLogger", out  intOut);<font size="2">

Label1.Text =

</font>

"Implementing Enterprise Library FlatFile" + intOut;<font size="2">

 

</font>

 

//int.Parse("TestLogger");

}

<font size="2">

 

</font>

 

catch (Exception  ex)

{

<font size="2">

 

</font>

 

bool rethrow = ExceptionPolicy.HandleException(ex, "ExceptionPolicy"); <font size="2">

 

</font>

 

if (rethrow)<font size="2">

{

</font>

throw; }

}

Thanks,

Ravi

May 15, 2009 at 6:11 AM

Hi,

You can do it like this, Is this what you mean?

            try

            {

                throw new Exception();

            }

            catch (Exception ex)

            {

                ex.Data.Add("Additional Details", "Details");

                bool rethrow = ExceptionPolicy.HandleException(ex, "EP");

                if(rethrow)

                    throw;

            }

 

 By doing this, if you will add a logging handler, the details that you've added in the exception will be added to the log in the extended properties.

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

May 15, 2009 at 8:21 AM

Thanks Dudan,

this is exactly what i need.