baxtardo wrote on Jun 17th, 2009, 2:33am:I feel the shame of multiple posts
You are not the only one, far from it. Phenomenon seems quite common since forum was upgraded. In the old forum there was a Delete message button (in the thread view), check if it is there (I don't create threads often, I can't verify right now...). Otherwise forum moderators will probably clean it up.
Quote:when using the parse function you must use a try and catch loop in case an exception is generated Even if running it will not generate an exception it still needs the routine.
Yes, that's the way Java works, it is called "checked exceptions" and it is quite controversial, lot of people think Java should have only unchecked exceptions (like ArithmeticException or ArrayOutOfBoundsException, they are runtime exceptions).
Checked exceptions force you to try/catch them (the compiler enforce the requirement) or to declare your method to throw the same exception.
Quote:when formatting the date back to the date stamp format yyyyMMdd [...] the catch/try routine is not necessary
One could call this inconsistency of design. In general, parsing an external string might throw an exception, and you want to catch it, eg. to display feedback to user (in an interactive application) and ask to do the input again. Or just to supply a default parsed value.
If format sees some unknown characters, in general it just ignore them (or leave them as is).
Quote:Is there any way of knowing which Java functions require exception handling code and which do not
1) Check the API: for example in
BufferedReader, we have:
Quote:public int read()
throws IOException
because I/O is unreliable (resource not available, permission issue, etc.).
2) Well, you mention it, you have a compiler error.
3) You use a smart IDE (like Eclipse or NetBeans) which warns you while you type, and can even automatically add the try/catch block! Perhaps PDE will do the same some day.