| Author |
try/catch best practice
|
Dudley Dawson
Ranch Hand
Joined: Dec 14, 2004
Posts: 57
|
|
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?
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
Any objection to: -
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
Anupam Sinha
Ranch Hand
Joined: Apr 13, 2003
Posts: 1088
|
|
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.
|
 |
Brian Spindler
Greenhorn
Joined: May 17, 2007
Posts: 29
|
|
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 ]
|
 |
 |
|
|
subject: try/catch best practice
|
|
|