to aiirii(aiirii) 因为初学这个控件 所以对你的解释还有些疑问在onException中,程序中出现未处理的exception就会被截获,你就可在里面处理记录! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~参考下面的代码:procedure TFormLog.LogException(Sender: TObject; E: Exception); var Filename: string; LogFile: TextFile; begin // prepares log file Filename := ChangeFileExt (Application.Exename, '.log'); // ~~~~~~~~~~~~~~~~~应用程序的名称 AssignFile (LogFile, Filename); if FileExists (FileName) then Append (LogFile) // open existing file else Rewrite (LogFile); // create a new one // write to the file and show error Writeln (LogFile, DateTimeToStr (Now) + ':' + E.Message); if not CheckBoxSilent.Checked then Application.ShowException (E); // close the file CloseFile (LogFile); end;procedure TFormLog.Button1Click(Sender: TObject); var a, b, c: Integer; begin a := 10; b := 0; c := a div b; ShowMessage (IntToStr (c)); end;procedure TFormLog.Button2Click(Sender: TObject); begin raise Exception.Create ('raise button pressed'); end;---------------------------------------------------- 每次Button1Click/Button2Click的点击事件执行完后,就会自动执行TFormLog.LogException 这是为什么 ?另外procedure TFormLog.LogException(Sender: TObject; E: Exception); ~~~~~~~~~~~~这是什么类型 ? 导致后面的 Writeln (LogFile, DateTimeToStr (Now) + ':' + E.Message); ~~~~~~~~~ 我就弄不明白了 能再仔细的教教我吗 ? 谢谢
raise呢,就是触发一个Exception,或者说引发一个Exception;一般是引发一个自定义的Exception
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~参考下面的代码:procedure TFormLog.LogException(Sender: TObject; E: Exception);
var
Filename: string;
LogFile: TextFile;
begin
// prepares log file
Filename := ChangeFileExt (Application.Exename, '.log');
// ~~~~~~~~~~~~~~~~~应用程序的名称
AssignFile (LogFile, Filename);
if FileExists (FileName) then
Append (LogFile) // open existing file
else
Rewrite (LogFile); // create a new one // write to the file and show error
Writeln (LogFile, DateTimeToStr (Now) + ':' + E.Message);
if not CheckBoxSilent.Checked then
Application.ShowException (E); // close the file
CloseFile (LogFile);
end;procedure TFormLog.Button1Click(Sender: TObject);
var
a, b, c: Integer;
begin
a := 10;
b := 0;
c := a div b;
ShowMessage (IntToStr (c));
end;procedure TFormLog.Button2Click(Sender: TObject);
begin
raise Exception.Create ('raise button pressed');
end;----------------------------------------------------
每次Button1Click/Button2Click的点击事件执行完后,就会自动执行TFormLog.LogException
这是为什么 ?另外procedure TFormLog.LogException(Sender: TObject; E: Exception);
~~~~~~~~~~~~这是什么类型 ?
导致后面的 Writeln (LogFile, DateTimeToStr (Now) + ':' + E.Message);
~~~~~~~~~
我就弄不明白了
能再仔细的教教我吗 ?
谢谢
Exception是系统自己定义的一个结构,在出错时,系统就将出错信息填写到相应的区域,你在处理时,就可提取你需要的信息!!
不知道你明白了吗??