我想在自己封装的dll中所有函数当某一个function有异常时,都会类似于有Application.OnException 的效果。主动通知我的dll的一个异常处理的function.
进行相关的异常处理。我不想在每个function里都加上
try
except
//异常处理的function
end
这样去做。这样太低效了。 dll是否也有一个可以指向自己定义异常处理函数的指过程过针呢。分不够可以再加。谢了。
进行相关的异常处理。我不想在每个function里都加上
try
except
//异常处理的function
end
这样去做。这样太低效了。 dll是否也有一个可以指向自己定义异常处理函数的指过程过针呢。分不够可以再加。谢了。
It is to my knowledge not possible to retrieve the line number and/or unit name in which the exception occured.
// application-global exception handlertype
TForm1 = class(TForm)
procedure MyHandler(Sender: TObject; E : Exception);
procedure FormCreate(Sender: TObject);
end;procedure TForm1.MyHandler(Sender: TObject; E : Exception);
begin
// E.message is of type string
toLogfile('Exception: ' + E.message);
// either close the application or eat the exception
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnException := MyHandler;
end;
我写的dll是由C#程式去调用,并不是由我自己写一个程式去调用dll,并且我不能要求C#的程式员去将C#的程式的异常句柄指到我dll里的处理function
procedure Dll.MyHandler(Sender: TObject; E : Exception);
begin
// E.message is of type string
toLogfile('Exception: ' + E.message);
// either close the application or eat the exception
end;我的dll只是C#程式中的某一个部分。
procedure ExceptHandler(ExceptObject: TObject; ExceptAddr: Pointer);