小编and*_*lov的帖子

尽管发生了未处理的异常,控制台应用程序已退出并显示代码 0 (0x0)

我正在编写非常简单的 .Net Framework (4.7) 控制台应用程序代码,并故意抛出未经处理的异常。但程序仍然以代码 0 (0x0) 退出,这应该表明成功完成。

根据 Microsoft 文档,此处的 默认值是 0(零),这表示该过程已成功完成。

我的问题是:我期待任何退出代码,但没有 0。有人可以解释一下我在这里缺少什么吗?

我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {                    
            throw new Exception("Throw an exception");

            Console.WriteLine("Finishing program");
            Console.ReadLine();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输出窗口(调试)消息:

ConsoleApp2.exe 中发生类型为“System.Exception”的未处理异常

抛出异常

程序“[7480] ConsoleApp2.exe”已退出,代码为 0 (0x0)。

多谢

c#

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1