Grails中的常见异常处理格式1.1 [英] Grails common exception handling in grails 1.1

查看:344
本文介绍了Grails中的常见异常处理格式1.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个请告诉我如何在grails version1.1中处理RunTimeExceptions。我遵循了以下教程。我无法使其正常工作。



http://blog.bruary.net/2008/03/grails-custom -exception-handling.html



我有MyException扩展了RunTimeException。如果这个特殊的异常我想显示不同的错误页面。它可以实现grails 1.1版本?

解决方案

可以提供一些示例代码,其中抛出一些RuntimeException?
如果你不明白你的确切问题,很难正确地回答你的问题。



从这一点我可以告诉你,你的BootStrap.groovy应该是这样的:

  class BootStrap {
def exceptionHandler

def init = {servletContext - >

exceptionHandler.exceptionMappings =
['NoSuchFlowExecutionException':'/ my / doIt',
'java.lang.Exception':'/ error',
' org.you.YourCustomException':'/ yourErrorController / yourErrorAction']
}

def destroy = {}

另一方面,在您的代码中,您必须抓住发生的RuntimeExceptions并将其转换为您的自定义异常。



这里我们有趣的是:为什么要这样做?
抛出RuntimeExceptions时重定向不会更舒适吗?


Some one please tell me how to handle RunTimeExceptions in grails version1.1 .I have followed the following tutorial.I could not get it working.

http://blog.bruary.net/2008/03/grails-custom-exception-handling.html

I have MyException which extends RunTimeException .If this particular exception comes I want show different error page.Is it possible to achieve in grails 1.1 version?

解决方案

Can you provide some sample code, where some RuntimeException is thrown? It is difficult to answer your question properly, if you don't tell what your exact problem is.

As far as I could tell your from this point, your BootStrap.groovy should look something like this:

class BootStrap {
 def exceptionHandler

 def init = { servletContext ->

   exceptionHandler.exceptionMappings =
       [ 'NoSuchFlowExecutionException' :'/my/doIt',
         'java.lang.Exception' : '/error',
         'org.you.YourCustomException' : '/yourErrorController/yourErrorAction' ]
}

def destroy = { }

On the other side, in your code, you have to catch occuring RuntimeExceptions and transate them into your custom exception.

And here we are at the interesting point: Why do you want to do this? Wouldn't it be much more comfortable to redirect when RuntimeExceptions are thrown?

这篇关于Grails中的常见异常处理格式1.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆