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

How do you exit a method so that no other code is excecuted?

Enthusiast ,
Nov 14, 2008 Nov 14, 2008
How do you exit a method so that no other code is excecuted?
<cfif REFind("^[a-zA-Z0-9]+$", arguments.field) >

get out of method

</cfif>
TOPICS
Getting started
480
Translate
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 14, 2008 Nov 14, 2008
<cfreturn something>

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
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
Engaged ,
Nov 14, 2008 Nov 14, 2008
<CFABORT>
or
<CFLOCATION="safeplace.cfm">

Lots of options....
Translate
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 14, 2008 Nov 14, 2008
> <CFABORT>
> or
> <CFLOCATION="safeplace.cfm">

Inside a method?

That's a bit of a grim suggestion, innit?

--
Adam
Translate
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
Community Expert ,
Nov 16, 2008 Nov 16, 2008
<cfthrow>

(which takes into account functions with void-return in their signature)

Translate
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 16, 2008 Nov 16, 2008
> <cfthrow>
>
> (which takes into account functions with void-return in their signature)

I still think that's a bit draconian. One should throw an exception if an
exceptional circumstance has occurred.

For VOID methods, a return (or <cfreturn>) without a value is fine.

--
Adam
Translate
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
Community Expert ,
Nov 16, 2008 Nov 16, 2008
I still think [<cfthrow>] a bit draconian.

Not at all. <cfthrow> fits here.

Nikos101's <cfif REFind("^[a-zA-Z0-9]+$", arguments.field)>
looks to me like an exceptional condition. A precondition fails, and so the method has to abort mission. In addition, the throw (or rethrow) enables you to propagate the reason for failure to the appropriate handler.




Translate
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 16, 2008 Nov 16, 2008
You could also display a text message.
Translate
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
Community Expert ,
Nov 16, 2008 Nov 16, 2008
LATEST
Displaying a message is just one form of returning. So far, I think throwing (and, possibly, rethrowing) answers Nikos101's question completely. The simplest case is as follows:

caller
=====
f();
<!--- handle failure --->

function f( ) {
<cfif REFind("^[a-zA-Z0-9]+$", arguments.field) ><!--- failure--->
<!--- throw--->
</cfif>
}

However, thowing also applies to an arbitrary sequence of function calls. To illustrate, consider the following function definitions. Suppose that f1 is reponsible for handling any failure of the Nikos101 condition. However, the failure occurs in f3.

function f1( ) {
f2();
<!--- handle failure --->
}

function f2( ) {
f3();
<!--- rethrow--->
}

function f3( ) {
<cfif REFind("^[a-zA-Z0-9]+$", arguments.field) ><!--- failure--->
<!--- throw--->
</cfif>
}

Then the throw/rethrow mechanism ensures that the failure will be propagated up the call stack to the appropriate handler, namely, f1. The functions f2 and f3 don't need to know anything about the failure.




Translate
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