This thread should give enough information on how to do what the OP asked.
Yes, you're right. Very informative.
---
I admit using exception is not my strong skill, I know exception is good for error-recovery mechanisms. I'm maybe wrong but I use different approach. Before starting, I check all the possibilities that may fails the process. If something go wrong, I will show a 'friendly' message to the user and stop all the next steps below (using Exit). Exception's error-recovery mechanisms sounds good (for programmers) but I don't think users will like to know the technical things. For example I prefer to show "sorry, the process failed, please contact the programmer" instead of "division by zero".
So basically, I do not need to know what kind the exception is, because I do not try to recover the process. I prefer to let the programmer (me) to debug the program instead of adding exception codes into the program and to let users to deal with it.
But I should not be stubborn. I will try to use (more) exceptions in my codes in the future. I am glad that my simple question can attracted lots of advices and I can see the valid points of them.
I introduced the idea of a boolean function.
Me too often use this 'trick'. In this case this function does not return boolean value because I'm writing a simple program and the function to read database field names is not the main feature. So if it fails, it simply fails and shows nothing no need to be verbose.
In my experience exception handling is best left for library and low-level code.
Interesting. I write libraries more than 'full' programs. I should learn more about exceptions.
Thanks all for sharing your experiences with exceptions. Each times I read this thread I gain more understanding. I bookmarked this thread, will come back and implement them in my codes.