There is nothing wrong with the code per-se. However, by throwing and catching just Exception, you can't be sure that it is that error that occures. In this limited case: sure. But it is good to do things right from the beginning. The fanciest way is to create your own exceptionclass that inherits Exception, and catch that. I case something else occures it will be caught (hopefulle) further up in the program. /Mike
how about the case when length is exactly equal to explicit length. I usually would code something like: Also, consider that when you throw your new Exception it gets caught by your second catch block. The end result of your code seems to be to hide the NumberFormatException, and to replace it with an IllegalArgumentException.
So how about throwing that instead of new Exception, and delete your second catch block?
Thanks for your comments. A couple of my comments: 1) This code is actually refactored from an existing codebase. So as I went about refactoring it to suit my needs, I had to come up with that nasty, throw new exception() to control the flow. According to the signature of the method; all exceptions need to be masked out as an IllegalArgumentException. So I'd prefer not to introduce another exception class into the mix. 2) (To: Mike Curwen) In the context of the method, length==explicitLength is ok and is processed later on after this try-catch scope. Pho [This message has been edited by Pho Tek (edited August 16, 2001).]
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
a bit of art, as a gift, that will fit in a stocking