except
捕捉到异常后,外层不会再捕捉到,外层finally
会执行
var
n: integer;
begin
try
try
try
n := StrToInt('test');
except
Memo1.Lines.Add('except')
end;
except
Memo1.Lines.Add('except 2')
end;
finally
Memo1.Lines.Add('finally')
end;
end;
{
except
finally
}
finally
不会捕捉异常,知识无论异常是否发生,都会执行,执行完后,外层继续可以捕捉到异常
try
try
try
n := StrToInt('test');
finally
Memo1.Lines.Add('finally')
end;
except
Memo1.Lines.Add('except')
end;
finally
Memo1.Lines.Add('finally 2')
end;
{
finally
except
finally 2
}
exit
相当于后面的代码注释掉不执行,不影响except
和finally
的行为
try
try
try
exit;
finally
Memo1.Lines.Add('finally')
end;
except
Memo1.Lines.Add('except')
end;
finally
Memo1.Lines.Add('finally 2')
end;
{
finally
finally 2
}
abort
也相当于注释后面的代码,不执行,但是会抛出异常,被外层except
捕捉到
try
try
try
abort;
finally
Memo1.Lines.Add('finally')
end;
except
Memo1.Lines.Add('except')
end;
finally
Memo1.Lines.Add('finally 2')
end;
{
finally
except
finally 2
}
halt
、Application.Terminate
等终止程序的代码,无视except
和finally
,不会触发,程序立刻终止。
PS:
Close会发生FormClose事件,FormCloseQuery事件
Halt会发生FormDestory事件,
Application.Terminate以上三个事件都不会发生