问题
How can i jump to the catch block in a try catch :
try{ if(bla!=) throws Exception(); }catch(exception){ //do }
doesn't work ?
回答1:
bla!=
should be followed by a condition, throws
should be throw
, Exception()
should be new Exception()
, exception
should be Exception e
try {
if (bla != null) // or anything else
throw new Exception("Exception thrown");
} catch (Exception e) {
System.out.println("Exception caught!");
e.printStackTrace();
}
回答2:
Look the Flow of a try-catch-finally
Block

来源:https://stackoverflow.com/questions/22790114/trycatch-jump-to-the-catch