Lucee 6, better cftry

what do you do when you have to test without cftry?
I guess like me. Add comments like these:

<!--- <cftry> ---->

    <cf_doSomething>

<!----
    <cfcatch type="any">
       <cfabort>
    </cfcatch>
</cftry>
---->

to avoid these comments you could add a “disabled” attribute to the tag to produce the same result:

<cftry disabled=true> 
    <cf_doSomething>

    <cfcatch type="any">
       <cfabort>
    </cfcatch>
</cftry>

you like it?

8 Likes

that does seem rather neat!

1 Like

Hi!

Good idea!

Now is it better to have a disabled attribute or an enabled attribute with default true?

<cftry enabled=false> 
    <cf_doSomething>

    <cfcatch type="any">
       <cfabort>
    </cfcatch>
</cftry>
2 Likes

It’s a good idea, instead of commenting out the try/catch, I usually add <cfrethrow> inside of the catch statement

5 Likes

I do really like it!!!

1 Like

yes, this is better :slight_smile:

we have the same for cfdump (<cfdump> :: Lucee Documentation)
“enabled:dumps are enabled by default, pass false to short circuit a dump execution and effectively disable it”

The handy thing with this is, you then can do the following in the Application.cfc

this.tag.cfdump.enabled=false;

to disable all dumps (unless tehex have set that attribute explicitly).

having “enabled” would be consistent with existing implementation (dump).

3 Likes

ok @Roberto_Marzialetti can you file an enhancement?

Done:
https://luceeserver.atlassian.net/browse/LDEV-3628
:slight_smile:

3 Likes

Hey,

you can also simply change cfcatch’s “type” attribute. It accepts arbitrary strings and cfcatch will only kick in if this “type” matches the exception’s actual type.

I usually do it like this:

<cftry> 
    <cf_doSomething>

    <cfcatch type="never_mind">
       <cfabort>
    </cfcatch>
</cftry>
1 Like

and in cfscript?

I’m not a heavy cfscript user, but I imagine this would be possible:

try (enabled=false) {
    x = 5/0;
}
catch (any e) {
    writeOutput("Error: " & e.message);
}

or depending on the standard established for the other tags in the cfscript for Lucee (ex: like thread in ACF9), this could also be

try enabled=false {
    x = 5/0;
}
catch (any e) {
    writeOutput("Error: " & e.message);
}

I prefer the first one.

1 Like

@micstriit Does this mean the enhancement might allow for

this.tag.cftry.enabled=false;
1 Like