gpt4 book ai didi

struct - ColdFusion 中 cfcatch 的类型

转载 作者:行者123 更新时间:2023-12-02 08:06:40 25 4
gpt4 key购买 nike

我只是使用 cftry/cfcatch block 来处理任何异常。以这个简单的异常(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>

上面代码的输出是这样的:

coldfusion.runtime.DivideByZeroException 
NO
YES
YES

我的问题是:

为什么 structKeyExists 没有抛出错误,因为 cfcatch 不是 struct 类型?

在转储cfcatch时,它看起来像是一个struct

任何建议。

最佳答案

我认为让您感到困惑的是您需要记住 ColdFusion 是一种无类型语言。

ColdFusion documentation on data types

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:

  • Simple One value. Can use directly in ColdFusion expressions. Include numbers, strings, Boolean values, and date-time values.
  • Binary Raw data, such as the contents of a GIF file or an executable program file.
  • Complex ** A container for data. Generally represent more than one value. ColdFusion built-in complex data types include arrays, structures, queries, and XML document objects. You cannot use a complex variable, such as an array, directly in a ColdFusion expression, but you can use simple data type elements of a complex variable in an expression. For example, with a one-dimensional array of numbers called myArray, you cannot use the expression myArray * 5. However, you could use an expression myArray3 * 5 to multiply the third element in the array by five.
  • Objects Complex constructs. Often encapsulate both data and functional operations. The following table lists the types of objects that ColdFusion can use, and identifies the chapters that describe how to use them:

所以 <cfcatch> 中的代码块包含一个可以称为“结构”的对象。默认情况下,该结构的名称是 cfcatch 。您可以通过指定 name 来覆盖该名称。 <cfcatch> 内的属性标签。

查看可用的所有内容的最简单方法是 <cfdump> <cfcatch>内的整个结构 block 。

<cfcatch>
<cfdump var="#cfcatch#">
</cfcatch>

CFCatch documentation on 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.

关于struct - ColdFusion 中 cfcatch 的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30618537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com