本文介绍了C#:异常处理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在try catch博客中捕获了一个异常.正在使用的方法是:

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>");
}



我面临的问题是异常显示时,前端显示导致异常的行和函数.

例如:-肥皂异常:在异常 .c:/bsb/exception.cs的第70行中找不到数据库

我不想以粗体显示文本.

请让我知道我该怎么做



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

推荐答案

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>");
      }



经过这些测试之后,我认为您可能会遇到多种错误消息,例如:
-ex.Source + ex.TargetSite + ex.Message
-ex.Source + ex.Message

第二种可能性是删除地址路径.但是,我认为这非常复杂,除非您确切地知道异常的外观.

另一种选择是创建自己的异常消息或类(并重写GetBaseException()),然后使用它.

希望这会有所帮助!



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!


try
{
//some code here;
}
catch(exception e)
{
response.clear();
response.Write("<h4 style="font-weight:normal;">" + e.message + "</h4>");
}



这篇关于C#:异常处理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:08