Visual Studio - 禁止某些“抛出异常”消息 [英] Visual Studio - suppress certain "Exception thrown" messages

查看:304
本文介绍了Visual Studio - 禁止某些“抛出异常”消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在某些方法的输出中隐藏异常抛出消息吗?



我使用HttpWebRequest进行服务器通信。我定期检查服务器是否可用(每秒几次)。当服务器不可达时HttpWebRequest抛出异常。我抓住它并将GUI元素设置为false。问题是当服务器无法访问时,输出窗口被Exception throwing消息混乱。



我知道您可以右键单击输出窗口,并取消选中异常消息。但是我不仅仅是一个在这个项目上工作的人,也许有人想要看到一些其他的异常消息。



我需要的例子:

  //继续显示异常抛出消息。 
static void Foo()
{
try
{
throw new Exception();
}
catch(异常e)
{
//进程异常
}
}

//抑制异常抛出消息。
static void FooSuppress()
{
try
{
throw new Exception();
}
catch(异常e)
{
//进程异常
}
}

static void Main [] args)
{
Foo();
FooSuppress();
}


解决方案

禁用异常消息:



(1)像您之前的回复一样,您可以在输出窗口中禁用它。



(2)您也可以在工具 - >选项 - >调试 - >输出窗口中禁用它。



(3)或者您可以使用调试菜单下的异常设置抛出异常 - > Windows->异常设置。



我没有找到其他解决方法来禁用它,除非你真的解决/处理你的代码中的异常。我使用VS2015版本进行测试。



没有其他好的建议,但是我可以帮助你在这里提交一个功能: https://visualstudio.uservoice.com/forums/121579- visual-studio-ide / suggestions / 16752127-visual-studio-suppress-certain-exception-thrown-me



你可以投票。 >

Can you hide "Exception thrown" messages in output for certain methods?

I use HttpWebRequest for server communication. I periodically check if the server is available (a few times every second). When a server is not reachable HttpWebRequest throws an exception. I catch it and set GUI elements enabled to false. The problem is when the server is unreachable, output window gets cluttered up with "Exception thrown" messages.

I know you can right-click output window and uncheck "Exception Messages". But I am not only one working on the project and there might be someone who wants to see some other exception messages.

Example of what I need:

// Keep showing "Exception thrown" message.
static void Foo()
{
    try
    {
        throw new Exception();
    }
    catch (Exception e)
    {
        // Process exception
    }
}

// Suppress "Exception thrown" message in this method.
static void FooSuppress()
{
    try
    {
        throw new Exception();
    }
    catch (Exception e)
    {
        // Process exception
    }
}

static void Main(string[] args)
{
    Foo();
    FooSuppress();
}

解决方案

To disable the Exception messages:

(1)Like your previous reply, you could disable it in the Output windows.

(2)You could also disable it under TOOLS->Options->Debugging->Output Window.

(3)Or you could just throw the Exception using the Exception Settings under Debug menu->Windows->Exception Settings.

I don't find other workaround to disable it unless you really resolve/handle the Exceptions in your code. I test it using the VS2015 version.

No other good suggestion, but I help you submit a feature here: https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/16752127-visual-studio-suppress-certain-exception-thrown-me

You could vote it.

这篇关于Visual Studio - 禁止某些“抛出异常”消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆