[英]Try except stops the service execution
List := FQueue.LockList;
for I := 0 to List.Count - 1 do
begin
Mail := TIdMessageTaskman(List[I]);
FEventLogger.LogMessage( 'Mail' + Mail.ToString, EVENTLOG_INFORMATION_TYPE , 0, 2);
try
try
FidSmtp.Connect();
FidSmtp.Send(Mail);
except
on e: exception do
begin
FEventLogger.LogMessage('Error sending mail ' + e.ClassName + ', ' +
e.Message, EVENTLOG_ERROR_TYPE, 0, 2);
MarkMailExecution(Mail.TaskID, Mail.NotificationID, False, e.Message);
Continue;
end;
end;
finally
begin
if FidSmtp.Connected then
FidSmtp.Disconnect;
end;
end;
FEventLogger.LogMessage( 'after finally', EVENTLOG_INFORMATION_TYPE , 0, 2);
MarkMailExecution(Mail.TaskID, Mail.NotificationID, True, '');
FreeAndNil(Mail)
So the following code works, but as soon as there is a problem sending an e-mail and the exception is raised, the service stops. 因此,以下代码可以正常工作,但是一旦发送电子邮件出现问题并且引发了异常,该服务就会停止。 Is there I way I can make it continue and go through all the Queue?
我有办法让它继续并通过所有队列吗? Even if there are messages with errors.
即使有错误消息。 For example of an error that stops my service is when "I attach" a file that does not exist.
例如,当我“附加”一个不存在的文件时,导致我的服务停止的错误。
You said you've confirmed you get into the finally section. 您说过,您已经确认自己进入了“ 最后”部分。 So there are 3 possibilities:
因此,存在3种可能性:
A line of code in the finally section blocks the code from continuing. 最终部分中的一行代码阻止了代码继续。
Another exception is raised in finally section. 在“ 最后”部分提出了另一个例外。
When you enter the finally section, you're already in an "exception state". 当您进入finally部分时,您已经处于“异常状态”。 So leaving finally takes you to the next finally/except section in the call stack.
因此,离开final将带您进入调用堆栈中的下一个finally / except部分。
You'll have to add debug logging to confirm which, but I suspect number 3. Possible triggers for the existing exception state: 您必须添加调试日志记录以确认哪个,但是我怀疑是3。现有异常状态的可能触发器:
Your Mail
instance is not valid, and your swallower caught an Access Violation. 您的
Mail
实例无效,并且吞下了访问冲突。 When you again try to use Mail
in the except section, you get another Access Violation. 当您再次尝试使用除外部分中的
Mail
时,您将收到另一个访问冲突。
Something within MarkMailExecution
triggers its own exception. MarkMailExecution
某些内容会触发其自身的异常。
(I'm assuming your logging mechanism isn't failing because you have been getting some information from it.) (我假设您的日志记录机制没有失败,因为您已经从中获取了一些信息。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.