【发布时间】:2013-03-11 05:51:07
【问题描述】:
我目前正试图通过在 Application.cfc 中包含以下代码来捕获我的应用程序中的所有错误:
<cffunction name="onError">
<!--- The onError method gets two arguments:
An exception structure, which is identical to a cfcatch variable.
The name of the Application.cfc method, if any, in which the error
happened. --->
<cfargument name="Except" required=true/>
<cfargument type="String" name = "EventName" required=true/>
<!--- Log all errors in an application-specific log file. --->
<cflog file="#THIS.NAME#" type="error" text="Event Name: #Eventname#" >
<cflog file="#THIS.NAME#" type="error" text="Message: #Except.message#">
<!--- Throw validation errors to ColdFusion for handling. --->
<cfif Find("coldfusion.filter.FormValidationException", Arguments.Except.StackTrace)>
<cfthrow object="#Except#">
<cfelse>
<cfoutput>
<h1>#Eventname#</h1>
</cfoutput>
<cfdump var="#Except#">
</cfif>
</cffunction>
其中一些是从我见过的其他示例中借用的(我不完全理解)。我最终想展示某种优雅的错误页面来征求用户的反馈,然后记录/发送错误。这似乎捕获了很多错误,但不是全部。如果我不需要,我也不想在任何地方使用 try/catch。有什么建议吗?
【问题讨论】:
-
它没有发现什么错误?它应该捕获该应用程序中的所有异常。
-
@AdamCameron,好吧,我应该对此进行限定,并说我在 onError 下的代码似乎没有处理一些错误。似乎我记得几个错误,其中错误的方法和转储没有像预期的那样输出。我不记得在什么情况下,所以我需要玩一下,看看我是否可以复制。
-
这是一个关键信息,是的,是的。
-
@AdamCameron,看起来问题可能是因为我正在执行
以解决服务器端验证错误。我从文档中复制了那段代码,但并没有真正理解它是什么。 -
不是您问题的答案,但可能有用 - 您可能想调查 BugLogHQ - 比简单的 cflog 提供更多可见性,包括设置错误优先级和阈值电子邮件通知等。
标签: coldfusion railo cfml application.cfc