ash*_*999 15 delphi exception-handling
在Delphi中,你如何才能最终使用try,并一起使用?Java/C#等价物看起来像:
try {
// Open DB connection, start transaction
} catch (Exception e) {
// Roll back DB transaction
} finally {
// Close DB connection, commit transaction
}
Run Code Online (Sandbox Code Playgroud)
如果你在Delphi中尝试这个,你可以使用try/finally或try/except; 但从来没有三个在一起.我想代码如下(不编译):
try
// Open DB connection, start transaction
except on e: Exception do
begin
// Roll back transaction
end
finally // Compiler error: expected "END" not "finally"
begin
// Commit transaction
end
Run Code Online (Sandbox Code Playgroud)
mjn*_*mjn 18
在Delphi中,您可以使用以下模式:
// initialize / allocate resource (create objects etc.)
...
try
try
// use resource
...
except
// handle exception
...
end;
finally
// free resource / cleanup
...
end
Run Code Online (Sandbox Code Playgroud)
Eug*_*its 10
写
try
// allocate resource here
try
finally
// free resource here
end;
except
// handle exception here
end;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4433 次 |
最近记录: |