Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 错误消息,但仍在调试_C#_Visual Studio 2008 - Fatal编程技术网

C# 错误消息,但仍在调试

C# 错误消息,但仍在调试,c#,visual-studio-2008,C#,Visual Studio 2008,我没有这方面的代码。我的问题是,当我输入文本出现错误时,程序不再响应,我需要关闭程序并编辑代码。我想要的是,当出现错误时,会有一条消息,表明这部分代码是错误的,我无需关闭程序 谢谢。您需要的是用try-catch块捕获执行选项,并将错误保存到日志或显示在屏幕上 class Program { static void Main(string[] args) { try { throw new Exception("Oops,

我没有这方面的代码。我的问题是,当我输入文本出现错误时,程序不再响应,我需要关闭程序并编辑代码。我想要的是,当出现错误时,会有一条消息,表明这部分代码是错误的,我无需关闭程序


谢谢。

您需要的是用try-catch块捕获执行选项,并将错误保存到日志或显示在屏幕上

class Program
{
    static void Main(string[] args)
    {
        try
        {
            throw new Exception("Oops, somthing bad happened!"); //This is line 17
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
            //throw; //If you don't have this the code will continue executing after this point.
        }
    }
}
运行此程序时,将显示以下消息框

--------------------------- --------------------------- System.Exception: Oops, somthing bad happened! at Sandbox_Console.Program.Main(String[] args) in c:\Sandbox Console\Program.cs:line 17 --------------------------- OK --------------------------- --------------------------- --------------------------- 系统异常:哎呀,糟糕的事情发生了! 在c:\Sandbox Console\Program.cs中的Sandbox_Console.Program.Main(字符串[]args)处:第17行 --------------------------- 好啊 ---------------------------
查看第17行如何显示发生的错误,您也可以将该信息保存到日志文件中,以供以后阅读。

提供更多详细信息,如错误消息