Fra*_*mec 13 c# debugging exception visual-studio
你能否在某些方法的输出中隐藏"Exception thrown"消息?
我使用HttpWebRequest进行服务器通信.我会定期检查服务器是否可用(每秒几次).当服务器无法访问时,HttpWebRequest会抛出异常.我抓住它并将GUI元素设置为false.问题是当服务器无法访问时,输出窗口会被"Exception thrown"消息弄得乱七八糟.
我知道您可以右键单击输出窗口并取消选中"异常消息".但我不仅是一个从事该项目的人,而且可能有人希望看到其他一些异常消息.
我需要的例子:
// Keep showing "Exception thrown" message in this method.
static void Foo()
{
try
{
throw new Exception();
}
catch (Exception e)
{
// Process exception
}
}
// Suppress "Exception thrown" message when it is thown in this method.
static void FooSuppress()
{
try
{
throw new Exception();
}
catch (Exception e)
{
// Process exception
}
}
static void Main(string[] args)
{
Foo();
FooSuppress();
}
Run Code Online (Sandbox Code Playgroud)
编辑:
在工具/选项/调试中启用我的代码可能会有所帮助.
我们使用Npgsql访问PostgreSQL数据库,有些调用超时.每次调用timeouted"Exception thrown"都被写入输出窗口(并且有很多).只是我的代码阻止了这一点
要禁用异常消息:
(1)和您之前的回复一样,您可以在“输出”窗口中将其禁用。
(2)您也可以在工具->选项->调试->输出窗口下禁用它。
(3)或者您也可以使用“调试”菜单->“ Windows”->“异常设置”下的“异常设置”抛出异常。
我没有找到其他解决方法来禁用它,除非您在代码中真正解决/处理了异常。我使用VS2015版本进行了测试。
没有其他好的建议,但我可以帮助您在此处提交功能:https : //visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/16752127-visual-studio-suppress-certain-exception-thrown-我
你可以投票。