As Barney says, it depends on how you want to deal with it. In the
Mach-II.info sample app(which is available for download), I have a
userListener that goes through a userService that in turn invokes the
userDAO to create the user. I let the error propogate up to the
userListener and the createUser() looks like:
<cffunction name="createUser" access="public" returntype="void" output="false" >
<cfargument name="event" type="MachII.framework.Event"
required="yes" displayname="Event" hint="I am the current event" />
<cfset var user = arguments.event.getArg("user") />
<cfset var userData = user.getUserTO() />
<cfset var errors = structNew() />
<cftry>
<cfset
variables.userService.createUser(argumentcollection=userData,
dsn=variables.dsn, dbtype=variables.dbtype) />
<cfset announceEvent("createUser.success",
arguments.event.getArgs()) />
<cfcatch type="Database">
<cfif findNoCase("duplicate",cfcatch.detail) >
<cfscript>
errors.usernameExists = "That username has
been taken.";
user.setErrors(errors);
announceEvent("createUser.usernameExists",
arguments.event.getArgs());
</cfscript>
<cfelse>
<cfrethrow>
</cfif>
</cfcatch>
</cftry>
</cffunction>
What's interesting to note is that this can also be called via
Flash/RIA interface. In that situation the userListener is not in
play. The flash client will call the userService (via a web service
call) and a web service fault will be thrown and handled accordingly.
-Phil
On Thu, 4 Nov 2004 09:36:04 -0800, Barney Boisvert <[EMAIL PROTECTED]> wrote:
> It should be wherever your application can recover. The method that
> calls the DB is probably not going to know how to deal with the error
> in any meaningful way. The "right" method will probably be the same
> method that handles any other validation errors (the ones that are
> checked pre-INSERT), which is likely several steps above your actual
> database call.
>
> cheers,
> barneyb
>
>
>
> On Thu, 4 Nov 2004 11:28:30 -0600, Dawson, Michael <[EMAIL PROTECTED]> wrote:
> > At what level, then, should your code check for the database error?
> > Should it be within the actual method that performs the database call;
> > should it be in the code that calls the method?
> >
> > What is your plan?
> >
> > Thanks
> > M!ke
> >
> >
>
> --
> Barney Boisvert
> [EMAIL PROTECTED]
> 360.319.6145
> http://www.barneyb.com/blog/
>
> I currently have 0 GMail invites for the taking
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.com).
>
> An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
>
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]