ColdFusion不捕获NoClassDefFoundError [英] ColdFusion not catching NoClassDefFoundError

查看:195
本文介绍了ColdFusion不捕获NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ColdFusion 8.我想在ColdFusion中捕获一个 NoClassDefFoundError 异常,但我不能...它仍然失败,并记录错误的异常.log文件。这是我尝试的。

I am using ColdFusion 8. I would like to catch a NoClassDefFoundError exception in ColdFusion however I can't... It still fails and logs the error in the exception.log file. Here is what I tried.

<cftry>
    <cfset myJavaObject.myMethod()>
    <cfcatch type="any">
        <cfdump var="#cfcatch #">
    </cfcatch>
    <cfcatch type="java.lang.Throwable">
        Horrible exception.
        <cfdump var="#cfcatch #">
    </cfcatch>
</cftry>

但这不起作用。你能告诉我怎么做吗?我需要在特定的地方而不是在我的Application.cfc的 OnError 函数中捕获此错误。

But this does not work. Could you please show me how to do that? I need to catch this error at a particular place and not in the OnError function of my Application.cfc.

推荐答案

现在我已经有更多的咖啡,我不认为 cfcatch 能够捕获 NoClassDefFoundError 。根据文档,它仅处理例外

Now that I have had more coffee, I do not think cfcatch is capable of catching a NoClassDefFoundError. According to the documentation, it only processes Exceptions:


异常是在ColdFusion页面中中断指令
正常流程的事件,例如数据库操作失败,缺少
包含文件和开发人员指定的事件。

Exceptions are events that disrupt the normal flow of instructions in a ColdFusion page, such as failed database operations, missing include files, and developer-specified events.

NoClassDefFoundError 错误


错误表示合理应用程序
不应尝试捕获的严重问题

An Error indicates serious problems that a reasonable application should not try to catch

听起来像 cfcatch 只是为了处理正常的可恢复问题。一旦你得到一个 NoClassDefFoundError ,你真的没有什么可以做。这是一个严重的错误,你不能经过它(在正常情况下)。你能做的最多的是显示一条错误信息并退出。

It sounds like cfcatch was only designed to handle normal "recoverable" problems. There is really not much you can do once you get a NoClassDefFoundError. It is a severe error and you cannot get past it (under normal circumstances). The most you can do is show an error message and exit.

Application.onError 似乎处理未捕获的错误,如 NoClassDefFoundError 以及异常。所以我认为最好的做法是实现 onError 并显示一个错误页面。

Application.onError seems to handle uncaught Errors like NoClassDefFoundError, as well as Exceptions. So I think the best you can do is implement onError and have it display an error page.

    <!---- test code --->
    <cfset myJavaObject = createObject("java", "path.to.MyClass") />
    <cfset myJavaObject.myMethod() />

    <!---- Application.cfc --->
    <cfcomponent>
         .... settings ...
         <cffunction name="onError" returnType="void"> 
             <cfargument name="Exception" required="true" /> 
             <cfargument name="EventName" type="string" required="true" /> 
             <h1>onError Test</h1>
             <cfdump var="#Exception#" />
         </cffunction>
    </cfcomponent>

    // test class
    public class MyClass {
        public void myMethod() {
            throw new NoClassDefFoundError ("Testing...");
        }
    }






更新


Any类型包括
java.lang的Java对象类型的所有错误。例外。它不包括java.lang.Throwable错误。
要捕获Throwable错误,请在cfcatch
标记类型属性中指定java.lang.Throwable

The Any type includes all error with the Java object type of java.lang.Exception. It does not include java.lang.Throwable errors. To catch Throwable errors, specify java.lang.Throwable in the cfcatch tag type attribute

文档说,捕获 Throwable 在我的任何测试(或你的)不工作。这强烈建议在行为或文档中的错误。无论如何,它不是工作作为广告,如上所述,唯一的选择我知道是使用一个一般的错误处理程序。如果由于某种原因您必须坚持使用Application.cfm文件,请尝试使用 < cferror type =exception...>

Despite what the documentation says, catching Throwable does not work in any of my tests (or yours). That strongly suggests a bug in the behavior or the documentation. Either way it does not work as advertised, so as mentioned above, the only alternative I know of is using a general error handler. If you must stick with an Application.cfm file for some reason, try using <cferror type="exception" ...>

(Absurd )测试用例:

<cftry>
   <cfset myJavaObject = createObject("java", "path.to.MyClass")>
   <cfset myJavaObject.myMethod()>
   <cfcatch type="java.lang.NoClassDefFoundError">
      CAUGHT java.lang.NoClassDefFoundError
   </cfcatch>
   <cfcatch type="java.lang.LinkageError">
      CAUGHT java.lang.LinkageError
   </cfcatch>
   <cfcatch type="java.lang.Error">
      CAUGHT java.lang.Error
   </cfcatch>
   <cfcatch type="java.lang.Throwable">
      CAUGHT java.lang.Throwable 
   </cfcatch>
   <cfcatch type="any">
      CAUGHT ANY
   </cfcatch>
   <cfcatch>
      CAUGHT
   </cfcatch>
</cftry>

这篇关于ColdFusion不捕获NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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