- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 try-catch 语句中有一个 try-catch 语句。内层catch捕获错误,但out catch语句中throw并没有导致错误被捕获。 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
}
}
当我运行脚本时没有出现任何错误,但我注意到我尝试填充的 SQL Server 数据库缺少数据。当我在调试中重新运行脚本时,函数“putStuffInDB”有一个在 catch block 中被捕获的错误。但是当我踩到消息时,它并没有“抛出”到外部 catch block ,而是处理了 finally block 并终止了。
我显然遗漏了一些我没有看到的东西。我过去在 C# 中使用过该构造,并且从未遇到过将错误“传递”到外部 catch block 的问题。
最佳答案
我没有看到这种行为。我在 PowerShell ISE 中运行了以下命令,它产生了预期的结果。数据库中的错误有没有可能实际上没有作为异常抛出?例如,我相信在 SQL Server 中,给定错误级别下的某些错误不会作为异常返回给 ADO.NET 提供程序。
$ErrorActionPreference = 'Stop'
function Throw1 {
try {
Write-Host "Throw1.Try"
throw "Error from Throw1"
}
catch {
Write-Host "Throw1.Catch"
throw
}
finally {
Write-Host "Throw1.Finally"
}
}
function Throw2 {
try {
Write-Host "Throw2.Try"
throw "Error from Throw2"
}
catch {
Write-Host "Throw2.Catch"
throw
}
finally {
Write-Host "Throw2.Finally"
}
}
function Test {
try {
Throw1
Throw2
}
catch {
Write-Host $error[0]
}
}
Test
产生以下内容:
Throw1.Try
Throw1.Catch
Throw1.Finally
Error from Throw1
关于Powershell try/catch rethrow 不传播错误(Powershell 2.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4456863/
关于 java-7 功能“精确重新抛出”和 final Exception ex 有很多问题,我找不到我的问题的明确答案。 “精确重新抛出”和final Exception之间有什么关系? publi
在 Swift 2 中,以下函数不会编译,即使函数中的所有调用都不会抛出。 func function1(f: Optional U>, x: Optional) -> Optional {
本文整理了Java中xapi.util.X_Util.rethrow()方法的一些代码示例,展示了X_Util.rethrow()的具体用法。这些代码示例主要来源于Github/Stackoverfl
如果我有这样的代码: let result; try { result = doSomethingThatCanThrow(); } catch (e) { throw new Err
我无法理解精确重新抛出在 Java 7 及更高版本中的工作原理。正如 https://www.theserverside.com/tutorial/OCPJP-Use-more-precise-ret
如果有一个带有多个 catch block 的 try-catch,是否有办法将异常重新抛出到下一个(不是底层的)catch 子句? 例子: try { // some exception can
这是我的方法,当我尝试通过 sonarQube 分析我的代码时收到此错误: 异常处理程序应保留原始异常:记录或重新抛出此异常。 为什么会出现此错误,我不应该像我的方法一样捕获异常吗? 我的方法: fo
我对这两个主题非常不确定。我知道我应该对需要以相同方式处理的异常使用 multi-catch。但是为了什么目的我真的需要这样的东西。 private void something(String nam
如果我想捕获除给定类型之外的所有异常,并且这些特定类型将被重新抛出以在更高的上下文中被捕获,这样做会更好吗: try { //Code that might throw an exceptio
在将代码与 Maven 集成后,我正在运行 SonarQube 5 进行代码质量检查。 Sonar 提示我应该: Either log or rethrow this exception. 在下面的代
本文整理了Java中org.sonar.api.utils.text.XmlWriter.rethrow()方法的一些代码示例,展示了XmlWriter.rethrow()的具体用法。这些代码示例主要
我在 try-catch 语句中有一个 try-catch 语句。内层catch捕获错误,但out catch语句中throw并没有导致错误被捕获。 Breifly,我的脚本格式类似于: $Error
您好,我正在学习 express 和 passport,我试着做一个注册表单,当我尝试使用 MySQL 插入一行时,我收到了这个错误,但我的表正在正确更新。 passport.use( 'lo
是否有这段代码 try { opaque_function_that_might_throw_arbitrary_exception (); } catch (...) { throw
我在有两条 INSERT 指令的存储过程中使用 TRY CATCH block 。 如果出现问题,CATCH block 会负责回滚所有所做的更改并且它工作正常,除了一件事! 我的 ASP.NET 应
我遇到过我必须在流表达式中捕获所有已检查的异常。我读过非常流行的话题: How can I throw CHECKED exceptions from inside Java 8 streams? 并
以下两种代码在什么情况下不等价? { // some code, may throw and/or have side effects } try { // same code as abov
我正在使用 java 11 和 Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (X64) Jul 9 2008 14:17:44 版权所有 (c) 19
我有一个 WPF 应用程序,我在其中使用 System.Threading.Tasks 进行长时间运行的 WCF 调用。我通过向 Application.Current.DispatcherUnhan
public class TestException extends except2 { public static void main(String[] args)throws Except
我是一名优秀的程序员,十分优秀!