How does one catch a custom exception with try-catch
in cfscript?
<cffunction name="myFunction">
<cfset foo = 1>
<cfif foo EQ 1>
<cfthrow type="customExcp" message="FAIL!">
</cfif>
</cfif>
The try-catch
is in cfscript. What should go into the catch()
statement?
try {
myFunction();
} catch () {
writeOutput("Ooops");
}
James has pointed you to the docs in his answer, but he's missed the bit about you asking about custom exceptions. The syntax is:
try {
myFunction();
} catch (customExcp e) {
writeOutput("Ooops");
writeDump(e); // have a look at the contents of this
}
Note you can have as many catch
blocks as you like, for different exception types. Any exception type not explicitly caught will still be thrown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With