ColdFusion 没有捕捉到 NoClassDefFoundError

时间:2023-01-15
本文介绍了ColdFusion 没有捕捉到 NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ColdFusion 8.我想在 ColdFusion 中捕获 NoClassDefFoundError 异常,但是我不能...它仍然失败并在 exception.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.根据文档,它只处理 Exceptions:

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.onErrora> 似乎可以处理 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 对象类型的所有错误java.lang.异常.它不包括 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" ...>

(荒谬)测试用例:

<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:如果单词对于 textview 来说太长,则强制下一个单 下一篇:如何在 PrintStackTrace 后保持 CFEXECUTE 不挂起

相关文章

最新文章