0

我正在处理我的旧系统冷融合的旧代码,有没有办法我可以在 application.cfc 中定义 cfcatch 并捕获我的应用程序的所有错误

  • 函数名称

  • 查询名称

  • 代码行号

  • 模板名称

    快速调试,而不是在代码中到处编写。

应用程序开发人员在代码的任何地方都没有发现任何错误。我确实在代码的一些地方插入了 cfcatch,但还有很多工作要做,而且由于生产,我不想修改这么多代码。

我在数据库中插入 cfcatch 并向开发团队发送电子邮件。因为系统正在生产中。

4

1 回答 1

3

您可以使用cferror标记或onError将所有错误定向到给定的页面/功能。

如果使用cferror,异常将在error变量中传递。如果你使用OnError,它是一个参数。

为了帮助您,我自己的错误电子邮件包括以下内容。您会注意到我们有特殊处理来帮助指出空白可能已被传递到 sql 整数字段中的地方,这种情况发生的频率比我想承认的要多。

An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
Time: #dateFormat(now(), "short")# #timeFormat(now(), "short")#<br />

<!--- Smarter error catching for form fields --->   
<cfif (error.message contains "Invalid data '' for CFSQLTYPE CF_SQL_INTEGER") and isdefined("form")>
    <!--- This stores a list of the Id fields --->
    <cfloop collection="#form#" item="thisField">
        <!--- Get the last two characters of the field name --->
        <cfset lastTwoChars = right(thisField, 2)>
        <!--- Get the value of the field --->
        <cfset thisFieldValue = evaluate('form.#thisField#')>
        <!--- Check to see if this is an Id field and if it's value is blank. --->
        <cfif lastTwoChars eq 'Id' and thisFieldValue eq ''>
            <h3 style="font-weight: bold; color: red">#thisField# is blank and it's possibly an integer field.</h3>
        </cfif>
    </cfloop>
</cfif>

<cfdump var="#error#" label="Error">


<br/>
<cfdump var="#form#" label="Form">
<br/>
<cfdump var="#url#" label="URL">
<br/>
<cfdump var="#session#" label="session">
于 2016-02-26T16:22:50.587 回答