Status/Resolution/Reason: Closed/Withdrawn/
Reporter/Name(from Bugbase): Mark Mandel / Mark Mandel (mark.mandel)
Created: 06/02/2009
Components: Language, Exception Handling
Versions: 9.0
Failure Type: Unspecified
Found In Build/Fixed In Build: 0000 /
Priority/Frequency: Major / Unknown
Locale/System: English / Platforms All
Vote Count: 0
Problem:
This is complicated, but:
If an exception is thrown from within a CFC, from a UDF named 'throw', it can't be caught by a <cfcatch type="ExceptionType" /> statement.
I will provide the code below, and also in the forums as an attachment
Method:
index.cfm
--------------
<h1>Start exception test</h1>
<h2>script based, typed try/catch</h2>
<cfscript>
try
{
createObject("component", "Exception").init("This is my message", "This is my detail");
}
catch(exception.Exception exc)
{
writeoutput("<p> Caught! </p>");
}
</cfscript>
------------------
Exception.cfc
------------------
<cfcomponent hint="Base exception object" output="false">
<!------------------------------------------- PUBLIC ------------------------------------------->
<cffunction name="init" hint="Constructor" access="public" returntype="AbstractBaseException" output="false">
<cfargument name="message" hint="the message for the exception" type="string" required="No" default="#getMetaData(this).hint#">
<cfargument name="detail" hint="the detail for the exception" type="string" required="No">
<cfif StructKeyExists(arguments, "detail")>
<!---<cfthrow type="#getMetaData(this).name#" message="#arguments.message#" detail="#arguments.detail#">--->
<cfset throw(getMetaData(this).name, arguments.message, arguments.detail) />
</cfif>
<cfthrow type="#getMetaData(this).name#" message="#arguments.message#">
</cffunction>
<!------------------------------------------- PACKAGE ------------------------------------------->
<!------------------------------------------- PRIVATE ------------------------------------------->
<cffunction name="throw" access="private" hint="Throws an Exception" output="false">
<cfargument name="type" hint="The type of exception" type="string" required="Yes">
<cfargument name="message" hint="The message to accompany the exception" type="string" required="Yes">
<cfargument name="detail" type="string" hint="The detail message for the exception" required="No" default="">
<cfthrow type="#arguments.type#" message="#arguments.message#" detail="#arguments.detail#">
</cffunction>
</cfcomponent>
Result:
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3038779
Deployment Phase: Release Candidate
External Customer Info:
External Company:
External Customer Name: Mark Mandel
External Customer Email: 3EA9517D445A9E8999201549
External Test Config: 06/02/2009
Attachments:
Comments: