【发布时间】:2018-10-07 11:52:48
【问题描述】:
我正在尝试使用 beanshell try catch 脚本,但我遇到了困难。这么几个问题:
为什么当我尝试运行以下代码时收到错误,而不是 catch 语句“beanshell 中的错误?
String str = "a";
try {
log.info(str)
}
catch (Exception ex) {
log.error("Error in beanshell", ex);
throw ex;
}
错误:
2016/12/14 10:26:33 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of: ``String str = "a"; try { log.info(str) } catch (Exception ex) { log.error("Err . . . '' Encountered "}" at line 4, column 1.
2016/12/14 10:26:33 WARN - jmeter.protocol.java.sampler.BeanShellSampler: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``String str = "a"; try { log.info(str) } catch (Exception ex) { log.error("Err . . . '' Encountered "}" at line 4, column 1.
其次,当我运行这段代码时:
try {
String str = "a";
log.info(str)
}
catch (Exception ex) {
log.error("Error in beanshell", ex);
throw ex;
}
我收到此错误:
2016/12/14 10:27:25 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of: ``try { String str = "a"; log.info(str) } catch (Exception ex) { log.error("Er . . . '' Encountered "}" at line 4, column 1.
2016/12/14 10:27:25 WARN - jmeter.protocol.java.sampler.BeanShellSampler: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``try { String str = "a"; log.info(str) } catch (Exception ex) { log.error("Er . . . '' Encountered "}" at line 4, column 1.
同样,我不明白为什么 Catch 没有发挥作用。 另外 - Catch Exception/Throwable/EvalError 等有什么区别? 谢谢
【问题讨论】:
标签: error-handling jmeter try-catch beanshell