1. <cfif isDefined ( 'form.fieldNames' )>
  2. <!---
  3. This variable will collect errors.
  4. The form display will iterate over
  5. the array and display any errors
  6. that exist.
  7. --->
  8. <cfset variables.errors = arrayNew(1) />
  9. <cftry>
  10. <!---
  11. Field validation
  12. It's extremely annoying to show
  13. users one validation error message
  14. at a time. These should be collected
  15. and displayed en masse.
  16. --->
  17. <cfif [some field is not valid]>
  18. <cfset arrayAppend ( variables.errors, 'Invalid value message' ) />
  19. </cfif>
  20. <cfif [some other field is not valid]>
  21. <cfset arrayAppend ( variables.errors, 'Invalid value message' ) />
  22. </cfif>
  23. <cfif arrayLen ( variables.errors ) gt 0>
  24. <!---
  25. The throw will bypass any further
  26. processing without the need for an
  27. extended cfif block around all of
  28. that additional processing.
  29. --->
  30. <cfthrow type="validation" />
  31. </cfif>
  32. ... start processing ...
  33.     
  34. <!---
  35. Some processing needs to be isolated
  36. for specific error handling. Errors
  37. can be rethrown to the primary handler
  38. to skip further processing.
  39. --->
  40. <cftry>
  41. ... isolated processing ...
  42.         
  43. <cfcatch type="any">
  44. <cfrethrow />
  45. </cfcatch>
  46. </cftry>
  47.     
  48. ... continue processing ...
  49. <cfcatch type="validation">
  50. <!---
  51. Errors sent here are already in
  52. the errors array and can just be
  53. allowed drop to the form view for
  54. display.
  55. --->
  56. </cfcatch>
  57. <cfcatch type="any">
  58. <!---
  59. In the simplest cfcatch scenario,
  60. the error message can just be
  61. appended to the errors array.
  62. --->
  63. <cfset arrayAppend ( variables.errors, cfcatch.message ) />
  64. </cfcatch>
  65. </cftry>
  66. </cfif>