I know people say that one should only use exceptions in exceptional circumstances, but there are times when it seems to me that using try & catch would make my code a lot simpler than the alternative - a number of condtional return statements. Can the cost of throwing exceptions be avoided by instead of throwing a new exception, throwing a constant that extends the class Throwable?
E.g.
public class TestThrowable {
static final Throwable CONSTANT_THROWABLE= new Throwable(){};
public static void main(String[] args) {
try{
throw CONSTANT_THROWABLE;
}catch(Throwable t){
System.out.println("Caught the throwable!");
}
}
}
Luke