ColdFusion 中的 cfcatch 类型 [英] Type of cfcatch in ColdFusion
问题描述
我只是使用 cftry/cfcatch
块来处理任何异常.以这个简单的例外为例:
I am simply using a cftry/cfcatch
block for handling any exception. Take this simple exception:
<cftry>
<cfset abc = 1/0>
<cfcatch>
<cfdump var="#cfcatch.getClass().getName()#">
<cfdump var="#isStruct(cfcatch)#">
<cfdump var="#isObject(cfcatch)#">
<cfdump var="#structKeyExists(cfcatch, 'type')#">
</cfcatch>
</cftry>
而上面代码的输出是这样的:
And the above code's output is like this:
coldfusion.runtime.DivideByZeroException
NO
YES
YES
我的问题是:
为什么 structKeyExists
没有抛出错误,因为 cfcatch
不是 struct
类型?
Why structKeyExists
is not throwing an error as cfcatch
is not of type struct
?
在转储 cfcatch
时,它似乎是一个 struct
.
And on dumping cfcatch
it seems like it is a struct
.
任何建议.
推荐答案
我认为让您感到困惑的是您需要记住 ColdFusion 是一种无类型语言.
I think what is confusing you is that you need to remember that ColdFusion is a typeless language.
数据类型
ColdFusion 通常被称为无类型,因为您不将类型分配给变量,并且 ColdFusion 不将类型与变量名称相关联.但是,变量表示的数据确实具有类型,并且数据类型会影响 ColdFusion 评估表达式或函数参数的方式.ColdFusion 在计算表达式时可以自动将许多数据类型转换为其他数据类型.对于简单的数据,例如数字和字符串,在变量用于表达式或作为函数参数之前,数据类型并不重要.
ColdFusion 变量数据属于以下类型类别之一:
Data types
ColdFusion is often referred to as typeless because you do not assign types to variables and ColdFusion does not associate a type with the variable name. However, the data that a variable represents does have a type, and the data type affects how ColdFusion evaluates an expression or function argument. ColdFusion can automatically convert many data types into others when it evaluates expressions. For simple data, such as numbers and strings, the data type is unimportant until the variable is used in an expression or as a function argument.
ColdFusion variable data belongs to one of the following type categories:
- 简单的一个值.可以直接在 ColdFusion 表达式中使用.包括数字、字符串、布尔值和日期时间值.
- 二进制原始数据,例如 GIF 文件或可执行程序文件的内容.
- Complex ** 数据容器.一般代表多个值.ColdFusion 内置的复杂数据类型包括数组、结构、查询和 XML 文档对象.您不能直接在 ColdFusion 表达式中使用复杂变量(例如数组),但可以在表达式中使用复杂变量的简单数据类型元素.例如,对于名为 myArray 的一维数字数组,您不能使用表达式 myArray * 5.但是,您可以使用表达式 myArray3 * 5 将数组中的第三个元素乘以 5.
- 对象 复杂的构造.通常封装数据和功能操作.下表列出了 ColdFusion 可以使用的对象类型,并列出了描述如何使用它们的章节:
所以 <cfcatch>
块中的代码包含一个可以称为结构"的对象.默认情况下,该结构的名称是 cfcatch
.您可以通过在 <cfcatch>
标记中指定 name
属性来覆盖该名称.
So the code within the <cfcatch>
block contains an object that can be referred to as a "structure". By default the name of that structure is cfcatch
. You can override that name by specifying the name
attribute within the <cfcatch>
tag.
查看所有可用内容的最简单方法是<cfdump>
<cfcatch>
块中的整个结构.
The easiest way to see everything that is available to you is to <cfdump>
the entire structure within the <cfcatch>
block.
<cfcatch>
<cfdump var="#cfcatch#">
</cfcatch>
The cfcatch variables provide the following exception information:
cfcatch variable Content
cfcatch.type Type: Exception type, as specified in cfcatch.
cfcatch.message Message: Exceptions diagnostic message, if provided; otherwise, an empty string; in the cfcatch.message variable.
cfcatch.detail Detailed message from the CFML interpreter or specified in a cfthrow tag. When the exception is generated by ColdFusion (and not cfthrow), the message can contain HTML formatting and can help determine which tag threw the exception.
cfcatch.tagcontext An array of tag context structures, each representing one level of the active tag context at the time of the exception.
cfcatch.NativeErrorCode Applies to type = "database". Native error code associated with exception. Database drivers typically provide error codes to diagnose failing database operations. Default value is -1.
cfcatch.SQLState Applies to type = "database". SQLState associated with exception. Database drivers typically provide error codes to help diagnose failing database operations. Default value is 1.
cfcatch.Sql Applies to type = "database". The SQL statement sent to the data source.
cfcatch.queryError Applies to type ="database". The error message as reported by the database driver.
cfcatch.where Applies to type= "database". If the query uses the cfqueryparam tag, query parameter name-value pairs.
cfcatch.ErrNumber Applies to type = "expression". Internal expression error > number.
cfcatch.MissingFileName Applies to type = "missingInclude". Name of file that could not be included.
cfcatch.LockName Applies to type = "lock". Name of affected lock (if the lock is unnamed, the value is "anonymous").
cfcatch.LockOperation Applies to type = "lock". Operation that failed (Timeout, Create Mutex, or Unknown).
cfcatch.ErrorCode Applies to type = "custom". String error code.
cfcatch.ExtendedInfo Applies to type = "application" and "custom". Custom error message; information that the default exception handler does not display.
这篇关于ColdFusion 中的 cfcatch 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!