• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

handle throws with cferror

New Here ,
Nov 15, 2007 Nov 15, 2007

Copy link to clipboard

Copied

I would like to create an error handling system in our application. but I just cant get a simple prototype to work as it should.

lets say, I want to handle two kinds of errors by throwing exceptions. in case of the sendToDev exception I want an email to be sent to the developers. In case of the sendToSupport exception I want an email to be sent to the support.

Therefore, I define two kind of cferrors:

<cferror type="exception"
exception="sendToDev"
mailto="dev@foobar.com"
template="handleError.cfm">

<cferror type="exception"
exception="sendToSupport"
mailto="support@foobar.com"
template="handleError.cfm">

on the handleError.cfm the mailto-attribute will be used to generate the email to the right adress.

so far for the cferror-definitions in application.cfm. now the throwing inside of some function in a cfc:

<cfif [condition]>
<cfthrow type="sendToDev" message="an error occured. mail to developers has been sent">
<cfelse>
<cfthrow type="sendToSupport" message="an error occured. mail to supporters has been sent">
</cfif>

my understanding of this:

depending on what I've defined as "type" when throwing the exception, the according cferror-tag should be used by the application. but it doesnt. whatever the condition is and whatever exception is thrown, it's allways the last defined cferror-tag which will be used by the application. in the described case, the sendToSupport-cferror will be used whatever is thrown. if i would define the sendToSupport-cferror first in the application-file, the sendToDev would be used.

any help here? i just dont get it :-(

regards

steven
TOPICS
Advanced techniques

Views

442

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 15, 2007 Nov 15, 2007

Copy link to clipboard

Copied

I think you will have better luck switching from application.cfm to application.cfc. Then instead of using cferror, you can put whatever code you want into the onError function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2007 Nov 16, 2007

Copy link to clipboard

Copied

hello and thanks for the reply.

we're actually using coldfusion mx 6, so I can't go for application.cfc at the moment, as it will take at least another half year until we start migration directoly to coldfusion 8.

therefore, I'd still be very pleased if you have any suggestions on my issue, as I really dont know if I'm missing something there. As for the custom exception: I dont have to create any java classes or components for the exceptions, right? only give the exceptions name when throwing and checking for it on cferror. that should be it, right?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 16, 2007 Nov 16, 2007

Copy link to clipboard

Copied

Hi,

What condition you have before your <cfthrow> statements?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2007 Nov 16, 2007

Copy link to clipboard

Copied

<cfif arguments.number lt 16>

very simple. only prototyping.

input is 12. so the sendToDev is throwed and the first cferror with mail dev@foobar.com should react. but the other one does. also, if the input is 17.

and if i declare the cferrors the other way round:


<cferror type="exception"
exception="sendToSupport"
mailto="support@foobar.com"
template="handleError.cfm">

<cferror type="exception"
exception="sendToDev"
mailto="dev@foobar.com"
template="handleError.cfm">

then, the sendToDev cferror is always called, not mattering what input I give.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 16, 2007 Nov 16, 2007

Copy link to clipboard

Copied

Hi,

Try something like this,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2007 Nov 16, 2007

Copy link to clipboard

Copied

LATEST
unfortunately, it doesnt change anything.

maybe I should just post you the whole prototype application as i run it here. i tried to keep it as simple as possible and added a short comment to describe what file is shown in the code, so you dont have to read thru a big bunch of code.

in this example with the input value 12, the output of the handleError.cfm looks like this:

msg: 12 - mail sent to dev.
mailto: support@foobar.com

of course, this is not what I would like to see. if cferror would react as wanted, the answer mailto should be dev@foobar.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation