내 응용 프로그램에 생성 된 예외를 처리하는 프로 시저가 있습니다. untThreadDSR에 예외가 생성되면 예외가 처리되어야하는 프로 시저에 의해 예외가 캡처되지 않습니다. 예외가 다른 양식에서 생성 된 경우 프로 시저가 올바르게 포착합니다.스레드에서 생성 된 예외를 잡아서 조작 할 수있는 방법은 무엇입니까
절차는 주요 데이터 모듈에 있습니다
...
private
{ Private declarations }
procedure HandleExceptions(Sender: TObject; E: Exception);
...
procedure DM.HandleExceptions(Sender: TObject; E: Exception);
begin
if pos('UNIQUE KEY',E.Message) <> 0 then
begin
if pos('UNQ_CUSTOMER_NAME',E.Message) <> 0 then
MsgMsg('Customer already registered.',2)
else if pos('UNQ_USERS_LOGIN',E.Message) <> 0 then
MsgMsg('User already registered.',2);
end else
if pos('ERROR_DATASYS',E.Message) <> 0 then
MsgMsg('The Server Date is incorrect. Please contact your network administrator!',2)
else //Other messages will be sent to Support
SendReport(E.Message, V_COMPANY, V_LOGIN, V_APP_VERSION, Sender);
end;
untThreadDSR 다음과 같이
unit untThreadDSR;
interface
uses
Classes, SysUtils, Messages, Windows, Forms;
type
TThreadDSR = class(TThread)
procedure DSR_Start;
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
uses untDM;
procedure TThreadDSR.DSR_Start;
begin
//I put this intentionally just to generate an exception
StrToInt('');
//If this is on any other form, the exception is caught by "HandleExceptions", but from here on out!
end;
procedure TThreadDSR.Execute;
begin
Synchronize(DSR_Start);
end;
end.
TThreadDSR가 호출 :
procedure TFrmDSR.btnExecuteClick(Sender: TObject);
var
Thread: TThreadDSR;
begin
Thread := TThreadDSR.Create(true);
Thread.FreeOnTerminate := true;
Thread.Resume;
end;
예외는 주 스레드에서 발생합니다. 너가 원하는게 그거야? –
"TThreadDSR"에서 생성 된 모든 예외가 "DM.HandleExceptions"에 걸리므로 오류 메시지를 처리 할 수 있기를 바랍니다. –