你如何确定 MkDir 抛出的异常?

How do you determine the exception being thrown by MkDir?

我正在使用 Mkdir from the Free Pascal System 单元。

如果已存在与传递给此过程同名的目录,则会发生错误。 $IOCHECKS compiler directive set to {$I-}, the program continues, but IOResult 设置为错误代码 5。如果没有 {$I-} 编译器指令,则会抛出异常。如果未被捕获,程序将以 return 代码 5 退出,反映错误。

我想捕获这个 SPECIFIC 异常,不管它的名称是什么。但是,我不知道如何找到引发的异常的确切名称。

注:我接受了给出的答案,但有一个说法我不同意:

Runtime error to exception conversion is a feature of sysutils.

在我的测试中,只需添加一个 try/except/end 部分即可停止标准运行时错误程序中止(向标准输出发送消息)。相反,程序流转到 "except..end" 块并在那之后继续。但是,如果不使用 SysUtils 单元,您将无法确定引发了哪个异常,因为那里定义了异常 类。

系统单元有一个名为 runerror 的基本 "terminate with errorcode" 例程,这就是您所看到的。这也不例外。看起来像这样:

[D:\testing]blaat
Runtime error 5 at [=10=]401437
  [=10=]401437
  [=10=]406E91

除了使用 ioresult 方法阻止它之外,这是不可恢复的

运行时错误到异常的转换是 sysutils 的一个特性。如果您已经使用 sysutils,它会引发 EInOutError 并且看起来像这样:

[D:\testing]blaat
 An unhandled exception occurred at [=11=]401557:
 EInOutError: Access denied
 [=11=]401557