If you're using DBGrid control then use it's error event to catch the error.