Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:40:12+00:00 2026-06-12T07:40:12+00:00

I have a form where I can upload logos a plenty. I’m validating files

  • 0

I have a form where I can upload logos a plenty. I’m validating files (empty form fields, wrong extension, …) inside a cftry/cfcatch statement.

When I find an error in the cftry, I do this:

 <cfthrow type="FileNotFound" message="#tx_settings_app_error_create_first#" />

and inside my ‘cfcatch’

 <cfcatch>
    <cfoutput><script type="text/javascript">window.onload = function(){alert("#cfcatch.message#");window.location.href="hs_apps.cfm"; } </script></cfoutput>
 </cfcatch>

This works fine, catches all errors and alerts the user what is wrong.

Now I wanted to use the same handler on a database call where I’m checking for duplicate username. Still the same:

 <cfquery datasource="#Session.datasource#" name="duplicates">
      SELECT a.app_alias 
      FROM apps AS a
      WHERE a.iln = <cfqueryparam value = "#Session.loginID#" cfsqltype="cf_sql_varchar" maxlength="13"> 
      AND a.app_alias = <cfqueryparam value = "#form.app_basic_alias#" cfsqltype="cf_sql_varchar" maxlength="50">
 </cfquery>
 <cfif duplicates.recordcount GT 0>
      <cfthrow type="FileNotFound" message="#tx_settings_apps_error_dup#" />
 </cfif>

The cfcatch is also the same.

However. This now procudes a server error page and I’m thrown out of the application.

Question:
Any idea, why I’m struggling to get cftry/cfcatch to work here? I’m clueless.

Thanks!

EDIT:
Here is the full code

<cfif isDefined("send_basic")>
    <cfset variables.timestamp = now()>
    <cfset variables.orderview = "1">

    <cfif form.send_basic_type EQ "new">
    <cftry> 
        <cfif module_check.recordcount GT 0>
            <cfloop query="module_check">
                <cfif module_check.module_name EQ "preorder">
                    <cfset variables.module_name = module_check.module_name>
                    <cfset variables.b2b_preord_ok = "true">
                </cfif>
            </cfloop>
            <cfif form.app_basic_orderview EQ "preo">
                <cfset variables.orderview = "0">
            </cfif>
        </cfif>

        <!--- PROBLEM HERE: DUPLICATES --->
        <cfquery datasource="#Session.datasource#" name="duplicates">
            SELECT a.app_alias 
                FROM apps AS a
                WHERE a.iln = <cfqueryparam value = "#Session.loginID#" cfsqltype="cf_sql_varchar" maxlength="13"> 
                AND a.app_alias = <cfqueryparam value = "#form.app_basic_alias#" cfsqltype="cf_sql_varchar" maxlength="50">
        </cfquery>
        <cfif duplicates.recordcount GT 0>
            <cfthrow type="FileNotFound" message="#tx_settings_apps_error_dup#" />
        </cfif>

        <!--- IF PASS, CREATE/UPDATE --->
        <cfquery datasource="#Session.datasource#">
            INSERT INTO apps ( ... )
            VALUES( ...  )
        </cfquery>
        <cfset variables.app_action = "Applikation erstellt">

        <!--- success --->
        <cfoutput><script type="text/javascript">window.onload = function(){alert("#tx_settings_app_cfm_create#");}</script></cfoutput>

        <cfcatch>
            <cfoutput><script type="text/javascript">window.onload = function(){alert("#tx_settings_app_err_create#");}</script></cfoutput>
        </cfcatch>
    </cftry>
<cfelse>
    <cftry>

        <!--- UPDATE --->
        <cfquery datasource="#Session.datasource#">
            UPDATE apps
                SET   ... = ...
        </cfquery>
        <cfset variables.app_action = "Applikation aktualisiert">
        <!--- success --->
        <cfoutput><script type="text/javascript">window.onload = function(){alert("#tx_settings_app_cfm_update#");}</script></cfoutput>
        <cfcatch>
            <cfoutput><script type="text/javascript">window.onload = function(){alert("#tx_settings_app_err_update#");}</script></cfoutput>
        </cfcatch>
    </cftry>        
</cfif>

</cfif>

The error message I’m getting it the message I specify =

 <cfthrow type="FileNotFound" message="#tx_settings_apps_error_dup#" />

Which if caught should alert the text behind tx_settings_apps_error_dup. If I dump the cfcatch, cfcatch.message is my specified text, so the error gets caught allright, only I get a server error page vs. an alert. I’m using exactly the same handler for fileuploads and form submits. I don’t get why it’s not working here?

Thanks for helping out!

WORKAROUD:
Note nice, but suffice(s):

<cfif dups.recordcount NEQ 0>
    <cfoutput><script type="text/javascript">window.onload = function(){alert("#tx_settings_apps_error_dup#"); location.href = "hs_apps_detail.cfm?create=newApp&id=none";}</script
    </cfoutput>
    <cfabort> 
</cfif>

So when a duplicate is found I alert the user, reload the exact same page and cfabort to prevent the old page from processing further. Patch that is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:40:14+00:00Added an answer on June 12, 2026 at 7:40 am

    (moved this down from being just a comment)

    OK, so the catch is definitely catching the exception if you’re able to dump it, so it’s not that the try/catch ain’t working, it’s something else. Bear in mind that processing will continue until the end of the request after your catch block, and only then will the output buffer be flushed, and your alert() sent to the browser. It sounds to me like after your output the alert, and processing continues, some OTHER error is occurring which is causing the server’s error page to display. I recommend getting rid of the error page temporarily and eyeballing the actual error CF is raising.

    NB: if you want processing to stop immediately in the catch block after you output the alert(), you’re going to need to tell CF that, ie: with a <cfabort>. Otherwise, as per above, it’ll just keep going.

    I think exceptions that are caught by the server error page are still logged in the exception log, but I could be wrong. You could always put an onError() handler in your Application.cfc, log whatever error occurred, then rethrow the error so the error page still deals with it. That way you get the info on the error, and the punter still sees the nice error page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have form where user can upload files via Ajax (and upload is
I have a form in my django app where users can upload files. How
I have a form which includes 3 textfields so users can upload files. They
I have a form where users can upload files, and I'd like to name
I have a form where users can upload Pdf files(about 30 pages to one
I have a form where users can upload Pdf files(about 30 pages to one
I have a form that contains two fields to upload files. I need to
I have a web application with an upload form where users can upload files.
I have an HTML web form where users can upload multiple files. I am
I have a form where the user can upload a zip file, it works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.