Generally RuntimeExceptions are exceptions that can be prevented programmatically. E.g NullPointerException
, ArrayIndexOutOfBoundException
. If you check for null
before calling any method, NullPointerException
would never occur. Similarly ArrayIndexOutOfBoundException
would never occur if you check the index first. RuntimeException
are not checked by the compiler, so it is clean code.
EDIT : These days people favor RuntimeException
because the clean code it produces. It is totally a personal choice.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…