Throwable this Java class is used to represent any class that can be thrown as an exception, Throwable can be divided into two types, error is used to denote compile-time and system error, and exception is the basic type that can be thrown.
1, RuntimeException
Public class Tree1 { publicstaticvoid f () { throwNew runtimeexception (); } Public Static void g () { f (); } Public Static void Main (string[] args) { g (); }}
Output Result:
Exception in thread "main" java.lang.RuntimeException at tree1.f (Tree1.java:6) at tree1.g ( Tree1.java:at tree1.main (tree1.java:14)
General exceptions need to be treated like this,
Try { ///may throw exception code } catch(Type1 id1) { // handling code for TYPE1 type exceptions } catch(Type2 id2) { ////handle type2 Type exception code }
RuntimeException is not a generic exception, it is a runtime exception that is automatically thrown by the Java Virtual machine and will be automatically captured.
However: exceptions of type runtimeexception (and its subclasses) can only be ignored in code, and the handling of other types of exceptions is enforced by the compiler, because in fact runtimeexception represents a programming error,
java--Standard Exceptions