7.3 Exception class and RuntimeException class
The relation and difference between exception class and RuntimeException class???
Example: A string becomes an integral type
Class:runtimeexceptiondemo01
Package Limethrowable._7_3; Public class RuntimeExceptionDemo01 { publicstaticvoid main (string[] args) { = "123"; int i = integer.parseint (str); * i);} }
Console:
15129
where parseint () signature:
Public Static int throws NumberFormatException
The parseint () method uses the throws keyword at the time of declaration, but does not use a try---catch when the method call is processed, why?
Observe the inheritance relationship of the NumberFormatException class:
It can be found that numberformatexception belongs to RuntimeException subclasses, then it is clear to know:
⊙exception must be handled in the program using a try---catch.
⊙runtimeexception can be handled without practical try---catch, but if there is an exception, the exception is handled by the JVM.
Tips:
For RuntimeException subclasses it is best to also use exception handling mechanisms.
Although the runtimeexception exception can be handled without a try---catch, it is sure to cause the program to break if an exception occurs, so that, in order to ensure that the program can still be executed after an error, Therefore, it is best to use the try---catch exception handling mechanism when developing code.
7.4 Custom Exception classes
La La la
Java--Exception capture and processing--Exception class and RuntimeException class