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

Why is my try/catch and onError() failing to handle invalid CFML construct errors?

New Here ,
May 29, 2014 May 29, 2014

Copy link to clipboard

Copied

I was playing around with different ways to set cookies and in the process I use the cfcookie tag wrong. It threw an error and the onError() sort of did its job. Rather than giving a nice clean error like normal, the page completely quit processing.

So I played around some more and tried this with out an onError() in the application.cfc.

<cftry>

    <cfset asdf = />

   

    <cfcatch type="any">

        <cfdump var="#cfcatch#">

    </cfcatch>

</cftry>

It threw the error as if the try/catch wasn't there. Is this normal and it has taken me years to notice it?

Phil

Views

366

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

correct answers 1 Correct answer

Community Expert , May 30, 2014 May 30, 2014

The behaviour you observe is the expected, and correct, one. The purpose of try/catch and onError is to catch exceptions.

ColdFusion compiles pages into executable code before running them. Strictly speaking, exceptions are errors that occur when ColdFusion runs already compiled CFML (CFM and CFC) pages.

However,  what happens when Coldfusion finds errors, for example, programming and syntax errors, during compilation? Such errors occur before ColdFusion converts the code to executable form. You t

...

Votes

Translate

Translate
Community Expert ,
May 30, 2014 May 30, 2014

Copy link to clipboard

Copied

The behaviour you observe is the expected, and correct, one. The purpose of try/catch and onError is to catch exceptions.

ColdFusion compiles pages into executable code before running them. Strictly speaking, exceptions are errors that occur when ColdFusion runs already compiled CFML (CFM and CFC) pages.

However,  what happens when Coldfusion finds errors, for example, programming and syntax errors, during compilation? Such errors occur before ColdFusion converts the code to executable form. You therefore cannot use try/catch or onError to handle them.

Coldfusion will report the errors that it finds during compilation as compiler errors.  That is what happens in your example. The line

  <cfset asdf = />

contains a programming error and so won't even compile. That is why you get a compiler error.

If you replace it with the line,

<cfset asdf = 2/0 />

you will get code that compiles, but which generates an exception.

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 ,
May 30, 2014 May 30, 2014

Copy link to clipboard

Copied

LATEST

I think the 3 60+ hour work weeks managed to shut down the part of my brain with 15+ years of CF development experience. Plus I got some sleep which always helps.

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