Delphi:Exception输出堆栈信息

在从C#转回Delphi 2009开发时,开发者发现Delphi的Exception缺少类似c#的StackTrace功能,用于定位错误行号。经过研究,发现Delphi的StackTrace为空,需要第三方库JEDI的JclDebug来获取。通过设置工程属性和使用特定代码,可以成功获取并处理程序Crash时的异常堆栈信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

起源:

用习惯了c#之Exception的StackTrace,在程序出异常crash时候能够以其定位出问题的模块及行号,用回Delphi 2009,发现没有这东西。

显然,在编译环境日新月异的今天,是不科学的。分析Delphi的Exception,发现些线索:StackTrace。

应该有戏!

继续下去,验证输出这个StackTrace,它是空的,里面没有预想要的内容。再深究去,发现并没想象那么容易,它扯到不少蛋。

 

1、Exception类

Delphi 2009中,StackTrace是如此定义的,与它一起的还有几个var:

  Exception = class(TObject)
  private
    ...
  protected
    ...
  public
    ...
    property StackTrace: string read GetStackTrace;
    property StackInfo: Pointer read FStackInfo;
{
    
    $IFDEF MSWINDOWS}
  class var
    // Hook this function to return an opaque data structure that contains stack information
    // for the given exception information record. This function will be called when the
    // exception is about to be raised or if this is an external exception such as an
    // Access Violation, called soon after the object is created.
    GetExceptionStackInfoProc: function (P: PExceptionRecord): Pointer;
    // This function is called to return a string representation of the above opaque
    //<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值