hi- i have a method that returns a string, which is derived from another method that throws an exception:
p.process() throws an exception. if I place it within a try/catch block, then val is only in scope within that try/catch block, and I cannot return it outside of the block. If i put the return inside the block, I then have to put some other default return outside the block. Seems sloppy. Is there an elegant way to do this?
Joined: Oct 30, 2001
Any objection to: -
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
Joined: Apr 13, 2003
I would prefer
If need be initalize val to a default value.
It depends a lot on the program flow as well. Throwing the exception forward may also be a good idea depedning on where should the exception be handled.
Joined: May 17, 2007
Yeah I agree with Anupam, if the exception is handled elsewhere you could write:
Or the same with handling in the method:
[ May 17, 2007: Message edited by: Brian Spindler ]