我在 try-catch 语句中有一个 try-catch 语句。内部 catch 捕获错误,但 throw 不会导致错误在 out catch 语句中被捕获。Breifly,我的脚本格式类似于:
$ErrorPreference = "Stop"
try
{
getStuffFromDB
putStuffInDB
}
catch
{
write-host ("Error: " + $error[0])
}
function getStuffFromDB
{
try
{
-- database query statement
}
catch
{
throw
}
finally
{
close connection and clean up
}
}
function putStuffInDB
{
try
{
-- database insert statements statement
}
catch
{
throw
}
finally
{
close connection and clean up
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行脚本时没有错误,但我注意到我试图填充的 SQL Server 数据库丢失了数据。当我在调试中重新运行脚本时,函数“putStuffInDB”有一个错误,该错误被捕获在 catch …