德尔福可以告诉我这个例外的例子的名字吗? [英] Can Delphi tell me the name of the routine that threw an exception?

查看:165
本文介绍了德尔福可以告诉我这个例外的例子的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在delphi(try..except / finally和e.message)中捕获异常,但是我想知道是否存在可以引发异常的异常处理机制,以及引发异常的例程的名称。例如

  procedure / function bla(); //这可以是一个单位/类
begin
code ....
这里提出一个错误 - >里面还是没有一个try-except / finally块
end;

,我会收到一条消息/对象/表示我提出错误'x'的任何东西在'bla'中。



我知道有关madexcept,还有另一种方式来捕捉异常吗?



我正在使用Delphi 7.解决方案可能适用于其他Delphi版本。

解决方案

您可以使用 ProcByLevel 函数从 JclDebug.pas 单元,它是 JCL



在使用前必须激活选项'插入JDBG数据从Ide菜单工具 - > jcl选项中的二进制'中。





然后你可以这样使用它

 使用
JclDebug;

procedure TForm18.Button1Click(Sender:TObject);
begin
try

raise Exception.Create('Hello from'+ ProcByLevel(0));
除了
在e:Exception do
ShowMessage(e.Message);
结束
结束

,结果就是这样的




I know how to catch exceptions in delphi (try..except/finally and e.message) but I want to know if there exists an exception handling mechanism which can raise the exception and also the name of the routine which raised it. by example

procedure/function bla();//this can be in a unit/class
begin
 code....
 an error  is raised here -> inside or not of an try-except/finally block 
end;

and I'll receive an message/object/anything that indicates me that error 'x' was raised in 'bla'.

I know about madexcept, there is another way to catch exceptions as they do?

I'm using Delphi 7. Solution may be applicable to other Delphi version also.

解决方案

You can use the ProcByLevel function from the JclDebug.pas unit wich is part of the JCL library.

before to use you must activate the option 'Insert JDBG data into the binary' from the Ide Menu tools->jcl Options.

and then you can use it in this way

Uses
 JclDebug;

procedure TForm18.Button1Click(Sender: TObject);
begin
    try

       raise  Exception.Create('Hello from '+ProcByLevel(0));
    except
         on e : Exception do
         ShowMessage(e.Message);
    end;
end;

and the result is something like this

这篇关于德尔福可以告诉我这个例外的例子的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆