本文介绍了< cfcatch>不“捕获”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像处理CFC来处理上传的图片。在该方法中,我使用 ImageNew()创建上传文件的新图像,然后根据需要调整其大小(以及一些其他验证,以确保它是一个图像)。这里是一段代码:

 < cftry> 
< cfset ImageScaleToFit(#local.uploadedImage#,72,,highestPerformance)>
< cfimage action =writesource =#local.uploadedImage#destination =#local.newThumbName#overwrite =yes>
< cfcatch type =any>
< cfset local.response ['catcher'] =#cfcatch.Detail#>
< cfset local.response ['success'] = false>
< cfreturn local.response>
< / cfcatch>
< / cftry>

在我将代码重新加载到生产服务器之后,它开始抛出一个错误,因为highestPerformance不是



作为< cftry> 的备份异常处理有Application.cfc给我一个电子邮件的详细信息,同时屏蔽用户的错误,如果'try'不能解决错误。



CFC < cftry> 捕获错误并将其发送回我的页面。



我的问题是,为什么这个特定的代码块不能使用< cftry> 并且错误被直接发送到我的Application.CFC中的异常处理?



是否有某种错误阈值,我的内置异常处理不能处理?



BTW,highPerformance工作原因虽然Adobe的文档highestPerformance是可用的选项...



编辑



这是我从Application.cfc获得的错误

无法初始化类javax.media.jai.JAI



和堆栈跟踪:



ava.lang.NoClassDefFoundError:无法在coldfusion.image初始化类javax.media.jai.JAI。 Image.resizeImageWithJAI(Image.java:1189)在coldfusion.image.Image.resize(Image.java:1119)在coldfusion.image.Image.scaleToFit(Image.java:974)在coldfusion.image.Image.scaleToFit(图像.java:959)at coldfusion.runtime.CFPage.ImageScaleToFit(CFPage.java:6189)at cfspecials2ecfc103515531 $ funcUPLOADFILEXHR.runFunction(C:\cfc\thecfc.cfc:143)在coldfusion.runtime.UDFMethod.invoke(UDFMethod .java:418)at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)at coldfusion.runtime.UDFMethod $ ReturnTypeFilter.invoke(UDFMethod.java:360)at coldfusion.runtime.UDFMethod $ ArgumentCollectionFilter.invoke(UDFMethod。 java:324)在coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59)在coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:277)在coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:192)在coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2471)在cfspecials2ecfc103515531 $ funcMULTIUPLOAD.runFunction(C:\cfc\thecfc.cfc:32)在coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:418)在coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)at coldfusion.runtime.UDFMethod $ ReturnTypeFilter.invoke(UDFMethod.java:360)at coldfusion.runtime.UDFMethod $ ArgumentCollectionFilter.invoke(UDFMethod.java:324)在coldfusion (coldFusion.Runtime.Runtime.TemplateProxy)上的coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:463)上的coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:277).filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59)。 invoke(TemplateProxy.java:453)在coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:320)在coldfusion.filter.ComponentFilter.invoke(ComponentFilter.java:183)在coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java :282)at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)在coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)在coldfusion.filter.PathFilter.invoke(PathFilter.java:86)在冷灌注.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)在coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)在coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)在coldfusion.filter.NoCacheFilter。 invoke(NoCacheFilter.java:46)在coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)在coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)在coldfusion.xml.rpc.CFCServlet.invoke(CFCServlet .java:138)在coldfusion.xml.rpc.CFCServlet.doPost(CFCServlet.java:289)在javax.servlet.http.HttpServlet.service(HttpServlet.java:760)在org.apache.axis.transport.http。 AxisServletBase.service(AxisServletBase.java:327)at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)at jrun.servlet.FilterChain.doFilter (FilterChain.java:86)at com.seefusion.Filter.doFilter(Filter.java:49)at com.seefusion.SeeFusion.doFilter(SeeFusion.java:1494)at jrun.servlet.FilterChain.doFilter(FilterChain.java: 94)at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)在coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)在jrun.servlet.FilterChain.doFilter(FilterChain.java:94)在jrun.servlet.FilterChain.service(FilterChain.java:101)at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)at jrun.servlet.JRunRequestDispatcher .jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)的jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)中的.invoke(JRunRequestDispatcher.java:286)在jrunx.scheduler.ThreadPool $ DownstreamMetrics。 invokeRunnable(ThreadPool.java:320)at jrunx.scheduler.ThreadPool $ ThreadThrottle.invokeRunnable(ThreadPool.java:428)at jrunx.scheduler.ThreadPool $ UpstreamMetrics.invokeRunnable(ThreadPool.java:266)at jrunx.scheduler.WorkerThread.run (WorkerThread.java:66)

解决方案

如果您使用ColdFusion 8,应用所有修补程序和更新。 CF 8有很多关于映像函数和标签的主要问题,如果Java导致下面的错误,CF可能无法捕获它。即使你不在CF 8,确保一切都更新。


I've got an image processing CFC to handle uploaded images. In the method, I'm creating an new image of the uploaded file with ImageNew() and then resizing it if needed (along with some other validation to make sure it's an image). Here's a snippet of the code:

<cftry>
        <cfset ImageScaleToFit(#local.uploadedImage#, 72, "", "highestPerformance")>
        <cfimage action="write" source="#local.uploadedImage#" destination="#local.newThumbName#" overwrite="yes" >
        <cfcatch type="any">
            <cfset local.response['catcher'] = #cfcatch.Detail#>
            <cfset local.response['success'] = false>
            <cfreturn local.response>
        </cfcatch>
    </cftry>

After I upoloaded the code to the production server it began throwing an error because "highestPerformance" isn't an available option for image compression on the production server.

As a backup for <cftry> exception handling I have the Application.cfc send me an email of the details while masking the errors from the user in the event the 'try' doesn't cathc the error.

Throughout the CFC the <cftry> catches the error and sends it back to my page. where it gets output to the console.

My question is, why does this particular block of code not work with <cftry> and the error gets sent directly to the exception handling in my Application.CFC?

Is there some sort of "error threshold" that my built-in exception handling can't handle?

BTW, "highPerformance" works for some reason even though the documentation at Adobe says "highestPerformance" is an available option...

EDIT:

Here's the error I'm getting from the Application.cfc

Could not initialize class javax.media.jai.JAI

And the stack trace:

ava.lang.NoClassDefFoundError: Could not initialize class javax.media.jai.JAI at coldfusion.image.Image.resizeImageWithJAI(Image.java:1189) at coldfusion.image.Image.resize(Image.java:1119) at coldfusion.image.Image.scaleToFit(Image.java:974) at coldfusion.image.Image.scaleToFit(Image.java:959) at coldfusion.runtime.CFPage.ImageScaleToFit(CFPage.java:6189) at cfspecials2ecfc103515531$funcUPLOADFILEXHR.runFunction(C:\cfc\thecfc.cfc:143) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:418) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:360) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:324) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:277) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:192) at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2471) at cfspecials2ecfc103515531$funcMULTIUPLOAD.runFunction(C:\cfc\thecfc.cfc:32) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:418) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:360) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:324) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:277) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:463) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:453) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:320) at coldfusion.filter.ComponentFilter.invoke(ComponentFilter.java:183) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:282) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:86) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.xml.rpc.CFCServlet.invoke(CFCServlet.java:138) at coldfusion.xml.rpc.CFCServlet.doPost(CFCServlet.java:289) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at jrun.servlet.FilterChain.doFilter(FilterChain.java:86) at com.seefusion.Filter.doFilter(Filter.java:49) at com.seefusion.SeeFusion.doFilter(SeeFusion.java:1494) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at jrun.servlet.FilterChain.service(FilterChain.java:101) at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106) at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42) at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286) at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543) at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203) at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320) at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428) at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266) at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

解决方案

If you are using ColdFusion 8 make sure that you have all hotfixes and updates applied. CF 8 had a lot of major issues with image functions and tags, and if Java is causing the error underneath CF might not be able to catch it. Even if you aren't on CF 8 make sure that everything is updated.

这篇关于&lt; cfcatch&gt;不“捕获”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 15:59