Reputation: 2650
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");
}
Upvotes: 5
Views: 3230
Reputation: 29870
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.
Upvotes: 9