当一个错误产生的时候,可以显示一个自定义的HTML页面。这就可以让用户在一个应用程序的功能和错误页面上保持一个一致的外观和感受。(Displays a custom HTML page when an error occurs. This lets you maintain a consistent look and feel among an application's functional and error pages.)
异常处理标签,可扩展性标签,应用框架标签(Exception handling tags, Extensibility tags, Application framework tags)
<cferror
template = "template path"
type = "exception|validation|request"
exception = "exception type"
mailTo = "e-mail address">
|
属性 |
必选/可选 |
默认 |
描述 |
|---|---|---|---|
| 模板
|
必选 |
|
指向自定义错误页面的相关路径(一个ColdFusion页面原先也被叫做一个模板)Relative path to the custom error page. (A ColdFusion page was formerly called a template.) |
|
类型
|
必选 |
|
自定义错误页面处理的错误的类型。这个类型也用来描述ColdFusion是怎样处理错误页面的。更多信息,请看ColdFusion Developer's Guide的 "Specifying a custom error page" 49 (Type of error that the custom error page handles. The type also determines how ColdFusion handles the error page. For more information, see "Specifying a custom error page" 49 in the ColdFusion Developer's Guide.)
|
|
例外
|
可选 |
any |
Type of exception that the tag handles: 这个标签处理的例外类型:
For more information on exception types, see cftry. 更多例外类型的信息,请看cftry |
|
mailTo |
可选 |
|
(An e-mail address. This attribute is available on the error page as the variable error.mailto. ColdFusion does not automatically send anything to this address).一个 e-mai地址。这个属性在错误页面上是作为一个错误变量.mailto。ColdFusion不会自动发送任何信息给这个地址。 |
在一个程序里使用这个标签为页面提供自定义错误信息。就算在错误发生的时候,它都可以让你在程序里保持一致的外观的感受。(Use this tag to provide custom error messages for pages in an application. This lets you maintain a consistent look and feel within the application, even when errors occur. )
一般情况下,你可以把这个标签内嵌在你的CFC程序或者是cfm文件程序,这样就可以为一个完整的程序指定错误处理的责任。如果指定的类型是"validation",那么你必须把它放在其中的一个文件中,ColdFusion会在其他的任意页面上忽略它。(You generally embed this tag in your Application CFC or Application.cfm file to specify error-handling responsibilities for an entire application. You must put it in one of these files if you specify type="validation"; ColdFusion ignores it on any other page. )
这个cftry和cfcatch标签提供比cferror标签更有互动性的方法在一个ColdFusion页面里处理ColdFusion错误,但是cferror标签是一个针对一般错误的好护卫。(The cftry and cfcatch tags provide a more interactive way to handle ColdFusion errors within a ColdFusion page than the cferror tag, but the cferror tag is a good safeguard against general errors. )
为了确保错误页面顺利地显示,要避免使用cfencode utility来对包含cferror标签的页面进行编码。(To ensure that error pages display successfully, avoid using the cfencode utility to encode pages that include the cferror tag.)
下列表格展示了你可以指定的错误,以及你可以在处理这些错误类型的页面上使用的代码。(The following table describes the types of errors you can specify and code you can use on the pages that handle these error type: )
|
页面类型 |
描述 |
使用方法 |
|---|---|---|
|
例外 |
当它侦测到一个不可处理的例外情况时,动态地用CFML 语言处理器来引用。(Dynamically invoked by the CFML language processor when it detects an unhandled exception condition.) 使用完整范围的CFML标签。错误变量必须放在cfoutput标签里。(Uses the full range of CFML tags. Error variables must be in cfoutput tags.) |
可以处理指定的例外类型或者展示例外的一般信息。(Can handle specific exception types or display general information for exceptions.) |
|
必选 |
把错误变量描述包含在错误变量段落中。(Includes the error variables described in the Error variables section. ) 不能包含 CFML 标签,但是你可以通过展示放在两个#号中的错误变量,比如#error.MailTo#.,这样就可以展示变量的值了。(Cannot include CFML tags, but you can display values of the error variables by enclosing them in number signs (#), as in #error.MailTo#.) |
Use as a backup error handler to other error handling methods, including exception type.像一个属于另外的错误处理方法的错误处理备份,包括了例外类型。 |
|
验证 |
处理数据输入确认错误发生时,你可以在提交表单时,利用隐蔽域来触发 不能包含CFML 变量,但是你可以通过展示放在两个#号中的错误变量,比如#Error.InvalidFields#.,这样就可以展示变量的值了。(Cannot include CFML tags, but you can display values of the error variables by enclosing them in number signs (#), as in #Error.InvalidFields#.) 你必须在cfc程序或者cfm文件程序中,指定变量错误处理。(You must specify the validation error handler in the Application.cfc or Application.cfm file. ) |
只是处理隐蔽域或者用onSubmit格式确认错误(Handles hidden form-field or onSubmit format validation errors only.) |
这些在cferror标签模板属性里指定的例外处理的页面包含了一个或者一个以上的错误变量。当一个错误发生时,ColdFusion替代了错误变量的值。(The exception-handling page specified in the cferror tag template attribute contains one or more error variables. ColdFusion substitutes the value of the error variable when an error displays.)
The following table lists error variables:下面的表格罗列了很多错误变量:
|
页面类型 |
错误变量 |
描述 |
|---|---|---|
|
Validation only只有验证 |
error.validationHeader |
Validation message header text. 验证讯息页眉文本。 |
|
error.invalidFields |
Unordered list of validation errors. 验证错误的无序名单。 |
|
|
error.validationFooter |
Validation message footer text. 验证讯息页脚文本。 |
|
|
Request and Exception |
error.diagnostics |
Detailed error diagnostics from ColdFusion MX.ColdFusion MX详细的错误诊断功能。 |
|
error.mailTo |
E-mail address (same as value in cferror.MailTo). E-mail 地址(和 cferror.MailTo中的值一样) |
|
|
error.dateTime |
Date and time when error occurred.错误发生的数据和时间。 |
|
|
error.browser |
Browser that was running when error occurred.错误发生时使用的浏览器 |
|
|
error.remoteAddress |
IP address of remote client.远程客户端的IP地址 |
|
|
error.HTTPReferer |
Page from which client accessed link to page where error occurred.错误发生时客户端登陆的页面链接 |
|
|
error.template |
Page executing when error occurred.发生错误时候的页面执行 |
|
|
error.generatedContent |
The content generated by the page up to the point where the error occurred.错误产生时页面产生的文本内容 |
|
|
error.queryString |
URL query string of client's request.客户端请求的URL query string |
|
|
Exception only |
error.message |
Error message associated with the exception.例外相关的错误信息 |
|
error.rootCause |
例外的发生根源。这个结构包含了被cfcatch标签返回的信息。比如说数据库例外,导致错误的SQL声明在 error.RootCause.Sql variable.中。对于Java例外来说,变量包含了Java servlet 的例外,这个例外是被 JVM做为例外发生根源来返回的。(The root cause of the exception. This structure contains the information that is returned by a cfcatch tag. For example, for a database exception, the SQL statement that caused the error is in the error.RootCause.Sql variable. For Java exceptions, this variable contains the Java servlet exception reported by the JVM as the cause of the "root cause" of the exception.) |
|
|
error.tagContext |
每个标签在标签stack包含的阵列结构信息。该信息stack包含了所有刚打开的每一个标签。Array of structures containing information for each tag in the tag stack. The tag stack consists of each tag that is currently open. |
|
|
error.type |
Exception type. |
Note: If type = "exception", you can substitute the prefix cferror for Error; for example, cferror.diagnostics, cferror.mailTo, or cferror.dateTime.
注意:如果类型= “例外”,你可以替代前缀cferror的错误。比如, cferror.diagnostics, cferror.mailTo, or cferror.dateTime。
<h3>cferror Example</h3>
<!--- Example of cferror call within a page.
NOTE: If you use cferror type="VALIDATION" you MUST put it in
Application.cfc or Application.cfm --->
<cferror type = "REQUEST"
template = "request_err.cfm"
mailTo = "admin@mywebsite.com">
<!--- This query calls a non-existent datasource, triggering an error to be handled. --->
<cfquery name="testQuery" datasource="doesNotExist">
select * from nothing
</cfquery>
<!--- Example of the page (request_err.cfm) to handle this error. --->
<html>
<head>
<title>We're sorry -- An Error Occurred</title>
</head>
<body>
<h2>We're sorry -- An Error Occurred</h2>
<p>
If you continue to have this problem, please contact #error.mailTo#
with the following information:</p>
<p>
<ul>
<li><b>Your Location:</b> #error.remoteAddress#
<li><b>Your Browser:</b> #error.browser#
<li><b>Date and Time the Error Occurred:</b> #error.dateTime#
<li><b>Page You Came From:</b> #error.HTTPReferer#
<li><b>Message Content</b>:
<p>#error.diagnostics#</p>
</ul>