gpt4 book ai didi

coldfusion - 使用 cfscript 捕获自定义异常

转载 作者:行者123 更新时间:2023-12-04 17:35:36 25 4
gpt4 key购买 nike

如何使用 try-catch 捕获自定义异常在 cfscript 中?

<cffunction name="myFunction">
<cfset foo = 1>

<cfif foo EQ 1>
<cfthrow type="customExcp" message="FAIL!">
</cfif>
</cfif>
try-catch在 cfscript 中。什么应该进入 catch()陈述?
try {
myFunction();
} catch () {
writeOutput("Ooops");
}

最佳答案

James 在他的回答中向您指出了文档,但他没有提到您询问自定义异常的内容。语法是:

try {
myFunction();
} catch (customExcp e) {
writeOutput("Ooops");
writeDump(e); // have a look at the contents of this
}

请注意,您可以拥有多个 catch根据您的喜好阻塞,用于不同的异常类型。任何未明确捕获的异常类型仍将被抛出。

关于coldfusion - 使用 cfscript 捕获自定义异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20547075/

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