我正在使用 Play 2.3.1 开发应用程序。我正在使用以下操作注释我的所有控制器:
@Override
public Promise<Result> call(final Context ctx) throws Throwable {
try {
return delegate.call(ctx);
} catch (MyCustomException e) {
return handleCustomException(e);
} catch (Exception e) {
return handleUnexpectedError(e);
}
}
此操作的目的是捕获控制器方法抛出的任何异常,以便向用户发送干净的消息。
MyCustomException
是我的应用程序特定异常扩展Exception
。
问题是即使我MyCustomException
在控制器的方法中抛出一个,相应的catch语句也永远不会执行。我总是有一个RuntimeException
由我的MyCustomException
.
结果是无论发生什么异常,用户总是看到由 . 发送的结果handleUnexpectedError(e)
。
我究竟做错了什么 ?谢谢。