anu*_*ine 5 velocity exception vtl user-defined
如何从Velocity Template Script(VTL)中抛出用户定义的异常?
从我的速度脚本,我需要根据条件抛出异常,以便调用者可以捕获异常并向最终用户提供有用的错误消息.
例如.
#if($passwordfield1 != $passwordfield2)
throw an exception here
#elseif($passwordfield1 == $passwordfield2)
do something
#end
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,如果passwordfield1和passwordfield2不匹配,则应抛出适当的异常,并且需要将其传播给最终用户.
有没有办法从速度脚本实现这一点?如果没有,请建议另一种方法.
context.put("exceptionThrower", new ExceptionThrower());
public class ExceptionThrower {
public void throwUserDefined() {
throw new UserDefinedException();
}
}
#if ($whatever)
$exceptionThrower.throwUserDefined()
#else
blah blah
#end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1427 次 |
| 最近记录: |