Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catch database truncate error

Status
Not open for further replies.

fdgsogc

Vendor
Feb 26, 2004
160
CA
Hi,
I want to catch a database truncate error and provide a very specific message that indicates the user is entering too much information. That is, I don't want to just catch the database error generally and say, "You have a database error.". The error code is 8152. Can I catch that specific code and then supply a custom error message.
 
It will depend on your current error handling method. But at a basic level, you could use a cftry/cfcatch around the query. Then check error variables like cfcatch.NativeErrorCode or cfcatch.SQLState and use the values to create a more informative error message. IIRC, some of these codes vary by vendor. So keep that in mind if you change database drivers.


Having said that, prevention is usually a far more efficient approach. There is no point executing a database query you know will generate an error. Validate the input first and reject any values that exceed your limits. Though you should still have error handling in place for exotic/totally unexpected errors.



----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top