delphi下使用jclDebug,在运行时显示详细的调试堆栈信息的范例
来源:互联网 发布:奇门排盘软件 编辑:程序博客网 时间:2024/06/08 14:33
delphi的异常信息比起java来太简单了,java的异常不但有错误提示,还有详细的堆栈信息甚至还能分级,可以一直追溯到最顶级的异常发生处,非常方便。相比较而言delphi的异常就太小儿科了。
不过jcl 提供的jclDebug多多少少的弥补了这个不足,通过jcldebug,也可以在运行时获取到详细的异常堆栈信息了。
这个功能简直太棒了,假如在24小时不间断运行的服务器上加上jclDebug,当错误发生时会自动记录出错的堆栈信息,开发人员可以分析错误发生时的状态和堆栈信息,根据堆栈信息中的错误代码行来修正错误。
这功能简直太棒了。
下面演示一下如何为程序加入jclDebug,使得程序可以获取详细堆栈信息
准备工作
1.安装jcl
2.安装jvcl
详细工作
窗口上放一个TApplicationEvents控件,并绑定OnException方法
代码如下
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, JclDebug, AppEvnts;type TForm1 = class(TForm) Button1: TButton; ApplicationEvents: TApplicationEvents; mmLogs: TMemo; procedure Button1Click(Sender: TObject); procedure ApplicationEventsException(Sender: TObject; E: Exception); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}//这是 TApplicationEvents.onException事件procedure TForm1.ApplicationEventsException(Sender: TObject; E: Exception);begin mmLogs.Lines.Add(DateTimeToStr(Now) + ' ' + e.ClassName); mmLogs.Lines.Add('错误原因: ' + e.Message); JclLastExceptStackListToStrings(mmLogs.Lines, False, True, True, False); mmLogs.Lines.Add(''); Application.ShowException(E);end;procedure TForm1.Button1Click(Sender: TObject);var x,y : Integer; z : double;begin x := 10; y := 0; z := x /y; ShowMessage(floatToStr(z));end;initialization Include(JclStackTrackingOptions, stRawMode); Include(JclStackTrackingOptions, stStaticModuleList); JclStartExceptionTracking;finalization JclStopExceptionTracking;end.
当按下button1的时候会发生一个除零异常,然后显示异常堆栈信息如下
2008-6-30 23:37:48 EZeroDivide
错误原因: Floating point division by zero
[0046E378] Unit1.TForm1.Button1Click (Line 45, "Unit1.pas" + 3) + $C
[0045206A] Forms.GetRealParentForm (Line 1897, "Forms.pas" + 3) + $8
[0043FE08] Controls.TControl.Click (Line 5229, "Controls.pas" + 9) + $8
[0042C862] StdCtrls.TButton.Click (Line 3745, "StdCtrls.pas" + 3) + $2
[0042C960] StdCtrls.TButton.CNCommand (Line 3797, "StdCtrls.pas" + 1) + $B
[0043F903] Controls.TControl.WndProc (Line 5146, "Controls.pas" + 83) + $6
[004438FB] Controls.TWinControl.WndProc (Line 7304, "Controls.pas" + 111) + $6
[0042C70C] StdCtrls.TButtonControl.WndProc (Line 3684, "StdCtrls.pas" + 13) + $4
[0043F590] Controls.TControl.Perform (Line 5021, "Controls.pas" + 5) + $C
[00443A4B] Controls.DoControlMsg (Line 7353, "Controls.pas" + 6) + $11
[00444443] Controls.TWinControl.WMCommand (Line 7616, "Controls.pas" + 1) + $5
[00457D10] Forms.TCustomForm.WMCommand (Line 5016, "Forms.pas" + 3) + $4
[0043F903] Controls.TControl.WndProc (Line 5146, "Controls.pas" + 83) + $6
[004438FB] Controls.TWinControl.WndProc (Line 7304, "Controls.pas" + 111) + $6
[00414F68] Classes.TThreadList.UnlockList + $4
[00424680] Graphics.FreeMemoryContexts (Line 5060, "Graphics.pas" + 12) + $5
[00454DFF] Forms.TCustomForm.WndProc (Line 3512, "Forms.pas" + 136) + $5
[00443024] Controls.TWinControl.MainWndProc (Line 7073, "Controls.pas" + 3) + $6
[0041BAE8] Classes.StdWndProc + $14
[004439F7] Controls.TWinControl.DefaultHandler (Line 7334, "Controls.pas" + 23) + $17
[00440228] Controls.TControl.WMLButtonUp (Line 5360, "Controls.pas" + 1) + $6
[0043F903] Controls.TControl.WndProc (Line 5146, "Controls.pas" + 83) + $6
[0041BAE8] Classes.StdWndProc + $14
[0044358D] Controls.TWinControl.WndProc (Line 7217, "Controls.pas" + 24) + $6
[00414F68] Classes.TThreadList.UnlockList + $4
[00424680] Graphics.FreeMemoryContexts (Line 5060, "Graphics.pas" + 12) + $5
[00443024] Controls.TWinControl.MainWndProc (Line 7073, "Controls.pas" + 3) + $6
[0044335F] Controls.TWinControl.IsControlMouseMsg (Line 7168, "Controls.pas" + 1) + $9
[004438FB] Controls.TWinControl.WndProc (Line 7304, "Controls.pas" + 111) + $6
[0042C70C] StdCtrls.TButtonControl.WndProc (Line 3684, "StdCtrls.pas" + 13) + $4
[00443024] Controls.TWinControl.MainWndProc (Line 7073, "Controls.pas" + 3) + $6
[0041BAE8] Classes.StdWndProc + $14
[0041C112] Contnrs.TComponentList.GetItems + $A
[0045CB7C] Forms.TApplication.ProcessMessage (Line 8105, "Forms.pas" + 23) + $1
[0045CB9E] Forms.TApplication.HandleMessage (Line 8124, "Forms.pas" + 1) + $4
[0045CE93] Forms.TApplication.Run (Line 8223, "Forms.pas" + 20) + $3
[0046FACD] Project1.Project1 (Line 13, "" + 4) + $7
其中的黑体部分就是出错的代码行了。
- delphi下使用jclDebug,在运行时显示详细的调试堆栈信息的范例
- Ubuntu下php在浏览器中调试信息的显示
- keil 中调用printf 的使用 在软件调试下 serial windows 下显示答打印信息
- 显示详细调试信息
- 输出程序Crash时的详细堆栈信息(四)
- 堆栈信息无法分析的调试总结
- 调试之堆栈的使用
- 使用dbghelp获取调用堆栈--release下的调试方法
- 使用dbghelp获取调用堆栈--release下的调试方法
- “使用多字节字符集”和“使用Unicode字符集”下的显示调试信息
- 数据结构--堆栈的范例程序
- ccpuid:CPUID信息模块。范例:显示所有的CPUID信息
- 一个简单的使用C++在运行时获取调用堆栈的类
- [原创]一个简单的使用C++在运行时获取调用堆栈的类
- 一个简单的使用C++在运行时获取调用堆栈的类
- 在delphi下TClientSocket的使用技巧
- delphi ocx在IE8下调试不能断点的问题
- Delphi程序在Xp Home下无法运行的问题
- 给应届毕业生的10条建议
- 数据结构(课本)c++版
- 解决IE下AJAX缓存问题的三种方法
- Lucene 基础
- VS2005自定义ActiveX控件在asp.net中应用方法
- delphi下使用jclDebug,在运行时显示详细的调试堆栈信息的范例
- 随想
- Spring结合Hibernate声明式事务配置
- TestDirector 8.0安装问题
- 关于aptana汉化 破解 支持中文 的方法
- 弹出窗口并向父页面返回值
- DSP错误总结!
- ACE 简单常用类整理(一)
- 数据库连接池满的问题