2 Replies Latest reply on Jan 8, 2007 9:16 AM by coldfuse228

    How to handle invalid urls...

    coldfuse228
      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
        • 1. Re: How to handle invalid urls...
          Level 7
          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.


          • 2. Re: How to handle invalid urls...
            coldfuse228 Level 1
            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