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

How to handle invalid urls...

New Here ,
Jan 08, 2007 Jan 08, 2007

Copy link to clipboard

Copied

Hi, on my page when a user clicks on my link <a href "getPic.cfm?id=12">, getPic.cfm would get id (12) and use it. However, if a user goes to url and manually types in a invalid id like "getPic.cfm?id=abc", it would cause an error. I'm a newbie to this, so I was wondering what are the basic ways to handle this, or any code samples would be a great help.

Thanks,
C
TOPICS
Advanced techniques

Views

278

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 ,
Jan 08, 2007 Jan 08, 2007

Copy link to clipboard

Copied

Hi, on my page when a user clicks on my link <a href
"getPic.cfm?id=12">, getPic.cfm would get id (12) and use it. However,
if a user goes to url and manually types in a invalid id like
"getPic.cfm?id=abc", it would cause an error. I'm a newbie to this, so
I was wondering what are the basic ways to handle this, or any code
samples would be a great help.

CF offers quite a few ways you can handle this issue. Which you choose
depends greatly where you want to trap the issue and how you want to
handle it.

There are validation functions you can use to test the value, such is
IsNumeric(), isDate(), isSimpleValue(), ect.

You could use <cfparm ...> and|or <cfqueryparm ...> to validate the
value and throw specific exceptions.

You could use <cftry><cfcatch> blocks around much of the above to trip
and handle exceptions at the local point.

You could use <cferror...> tags to handle exceptions at a more global level.

If you are using MX 7.x versions of CF, you can use the onError()
function of the Applicaiton.cfc.

You can set server wide exception handling scripts in the CF administrator.

This just scratches the surface over well designed application exception
handling. I find planning exception handling takes as much effort as
planning the program itself.


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 ,
Jan 08, 2007 Jan 08, 2007

Copy link to clipboard

Copied

LATEST
Thanks Ian, currently I am going with the try/catch way of handling errors. On errors, I would do a cflocation to my home page. Thanks so much for your details Ian!

-C

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