Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
I am catching an exception in try catch blog. The method am using is:
try
{
//some code here;
}
catch(exception e)
{
response.clear();
response.Write("<h4>"+e.message+"</h4>");
}


The issue I am facing is while the exception is displaying, in the front end it is displaying the line and function which is causing the exception.

eg.--soap exception:Data base not found at exception.GetInfo() in c:/bsb/exception.cs at line 70;

I dont want to display the text being displayed in bold.

Please let me know how can i do it
Posted
Updated 16-Jun-11 0:06am
v3
Comments
Slacker007 16-Jun-11 6:06am    
Edited for readability.
Monjurul Habib 16-Jun-11 18:38pm    
debug and provide the exact code.

Hello,

If I understand correctly, you wish to hide the path to the file generating the error, but still keep the source and error type.

I tried every error message using:

try
    {
        //generate error
    }
    catch (Exception ex) {
        Response.Clear();
        Response.Write("<h3> Data:" + ex.Data + "</h3>");
        Response.Write("<h3> HelpLink:" + ex.HelpLink + "</h3>");
        Response.Write("<h3> InnerException:" + ex.InnerException + "</h3>");
        Response.Write("<h3> Message:" + ex.Message + "</h3>");
        Response.Write("<h3> Source:" + ex.Source + "</h3>");
        Response.Write("<h3> StackTrace:" + ex.StackTrace + "</h3>");
        Response.Write("<h3> TargetSite:" + ex.TargetSite + "</h3>");
        Response.Write("<h3> ToString():" + ex.ToString() + "</h3>");
        Response.Write("<h3> GetBaseException():" + ex.GetBaseException() + "</h3>");
      }


After these tests, I think you may go for a combination of error messages, e.g.:
- ex.Source + ex.TargetSite + ex.Message
- ex.Source + ex.Message

A second possiblity is removing the address path. But, I think this is quite complicated, unless you know precisely how the exception looks like.

Another option would be to create your own exception message, or class (and override GetBaseException()), and use that.

Hope this helps!
 
Share this answer
 
v2
Perhaps this:


XML
try
{
//some code here;
}
catch(exception e)
{
response.clear();
response.Write("<h4 style="font-weight:normal;">" + e.message + "</h4>");
}
 
Share this answer
 
Comments
bsb25 16-Jun-11 6:25am    
i wanted the text being displayed in bold not to be displayed.NOt changing the bold to normal font
R. Giskard Reventlov 16-Jun-11 6:32am    
You were not clear! :-)
Use e.ToString() instead - it gives just the error message without the location context.

[edit]Typo: "without" written as "with" - OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
bsb25 16-Jun-11 6:16am    
its not working...
OriginalGriff 16-Jun-11 6:53am    
Show me the code that generate the error, and the exception handling code you actually used.
In your web.config, change
<compilation debug="true"></compilation>
to
<compilation debug="false"></compilation>


Let me know if it works!
 
Share this answer
 
v3
Comments
bsb25 16-Jun-11 7:31am    
nope :(
arathi_suresh 16-Jun-11 7:41am    
Instead of e.Message try using e.Source
bsb25 16-Jun-11 7:45am    
it will give only the exception source, not the message.

For ex for db exception its Database exception class.
check this out:

XML
try
{
//some code here;
}
catch(Exception ex)
{
Response.clear();
Response.Write("<h4>" + ex.Message.ToString() + "</h4>");
}
 
Share this answer
 
v3

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