Coldfusion 如何在应用程序崩溃或错误时获取函数名称和行号



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

  • 函数名称

  • 查询名称

  • 代码行号

  • 模板名称

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

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

IM 在 Databse 中插入 CFCATCH 并向开发团队发送电子邮件。 因为系统正在生产中。

您可以使用

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

最新更新