根据微软文档 此处 所述,默认值为 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();
}
}
}
输出窗口(Debug)消息:
发生了一个未处理的异常类型为'System.Exception'的异常在ConsoleApp2.exe中。
抛出一个异常。
程序“[7480]ConsoleApp2.exe”已以代码0(0x0)退出。
非常感谢。
Environment.ExitCode
,也不通过static int Main(…) { return <your-exit-code>; }
- 因此默认的退出代码适用。那么,框架如何知道每个特定异常的正确错误退出代码呢? - ckuri