默认情况下,异常被Application所捕获 在Application.Run里有这么一句 repeat try HandleMessage; except HandleException(Self); end; until Terminated; 而HandleException如下procedure TApplication.HandleException(Sender: TObject); begin if GetCapture <> 0 then SendMessage(GetCapture, WM_CANCELMODE, 0, 0); if ExceptObject is Exception then begin if not (ExceptObject is EAbort) then if Assigned(FOnException) then FOnException(Sender, Exception(ExceptObject)) else ShowException(Exception(ExceptObject)); end else SysUtils.ShowException(ExceptObject, ExceptAddr); end;而如果没有分配Application的OnException事件的话 就调用ShowException,ShowException调用MessageBox来显示一个错误对话框
在Application.Run里有这么一句
repeat
try
HandleMessage;
except
HandleException(Self);
end;
until Terminated;
而HandleException如下procedure TApplication.HandleException(Sender: TObject);
begin
if GetCapture <> 0 then SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
if ExceptObject is Exception then
begin
if not (ExceptObject is EAbort) then
if Assigned(FOnException) then
FOnException(Sender, Exception(ExceptObject))
else
ShowException(Exception(ExceptObject));
end else
SysUtils.ShowException(ExceptObject, ExceptAddr);
end;而如果没有分配Application的OnException事件的话
就调用ShowException,ShowException调用MessageBox来显示一个错误对话框
Project1.dpr,按住Ctrl,用鼠标点Application.Run的Run;