ColdFusion not catching NoClassDefFoundError

前端 未结 1 1500
感动是毒
感动是毒 2020-12-02 02:13

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 excep

1条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 02:51

    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:

    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 is an Error.

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

    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 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.

        
        
        
    
        
        
             .... settings ...
              
                  
                  
                 

    onError Test

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

    Update

    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

    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

    (Absurd) Test case:

    
       
       
       
          CAUGHT java.lang.NoClassDefFoundError
       
       
          CAUGHT java.lang.LinkageError
       
       
          CAUGHT java.lang.Error
       
       
          CAUGHT java.lang.Throwable 
       
       
          CAUGHT ANY
       
       
          CAUGHT
       
    
    

    0 讨论(0)
提交回复
热议问题