RHP*_*HPT 5 coldfusion try-catch cfml
如何try-catch在cfscript中捕获自定义异常?
<cffunction name="myFunction">
<cfset foo = 1>
<cfif foo EQ 1>
<cfthrow type="customExcp" message="FAIL!">
</cfif>
</cfif>
Run Code Online (Sandbox Code Playgroud)
该try-catch是CFSCRIPT.什么应该进入catch()声明?
try {
myFunction();
} catch () {
writeOutput("Ooops");
}
Run Code Online (Sandbox Code Playgroud)
詹姆斯在他的回答中指出了你的文档,但是他对你询问自定义异常有点遗憾.语法是:
try {
myFunction();
} catch (customExcp e) {
writeOutput("Ooops");
writeDump(e); // have a look at the contents of this
}
Run Code Online (Sandbox Code Playgroud)
请注意catch,对于不同的异常类型,您可以拥有任意数量的块.任何未明确捕获的异常类型仍将被抛出.