Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using below code in My Error page , its working fine but want to get the exact issue of exception ,to resolve it , How can I do this for the same..

What I have tried:

C#
if (ex != null)
                {
                    StringBuilder lasterror = new StringBuilder();


                    if (ex.Message != null)
                    {
                        lasterror.AppendLine("Message:");
                        lasterror.AppendLine(ex.Message);
                        lasterror.AppendLine();
                    }

                    if (ex.InnerException != null)
                    {
                        lasterror.AppendLine("<br>InnerException:");
                        lasterror.AppendLine(ex.InnerException.ToString());
                        lasterror.AppendLine();
                    }

                    if (ex.Source != null)
                    {
                        lasterror.AppendLine("<br>Source:");
                        lasterror.AppendLine(ex.Source);
                        lasterror.AppendLine();
                    }

                    if (ex.StackTrace != null)
                    {
                        lasterror.AppendLine("<br>StackTrace:");
                        lasterror.AppendLine(ex.StackTrace);
                        lasterror.AppendLine();
                    }
                    
                    lblException.Text = lasterror.ToString();
                }
Posted
Updated 23-Apr-18 22:43pm
v2
Comments
OriginalGriff 24-Apr-18 4:10am    
What do you mean by "want to get the exact issue of exception"?
The Exception object and int InnerException property (if any) provides all the information, so I'm confused as to exactly what you are having difficulty with.
Richard MacCutchan 24-Apr-18 4:17am    
if (ex != null)
If you are inside the catch block, then by definition ex must be a reference to the exception.; i.e. it cannot be null.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900