RuntimeException and its subclasses and errors (Error) do not have to be caught or thrown.
Java exceptions Throwable
are divided into two categories: Error
and Exception
. The Error class is an error that cannot be handled by the program itself.
Exception is divided into two categories: IOException
(non-runtime exception) and RuntimeException
(runtime exception). RuntimeException is to be avoided during program design. .
Except RuntimeException and its subclasses, other Exception classes and their subclasses are checkable exceptions. The compiler requires forced handling of this kind of exception, either try-cathch or throw it after the method name.
Uncheckable exceptions (exceptions that the compiler does not require forced handling): include runtime exceptions (RuntimeException
and its subclasses) and errors (Error
).
Exception This kind of exception is divided into two categories: runtime exception and non-runtime exception (compilation exception).
Runtime exceptions: They are all exceptions of the RuntimeException class and its subclasses, such as NullPointerException
(null pointer exception), IndexOutOfBoundsException
(subscript out-of-bounds exception) Etc. These exceptions are unchecked exceptions. You can choose to capture them in the program or not handle them.
These exceptions are generally caused by program logic errors, and the program should try to avoid the occurrence of such exceptions from a logical perspective.
The characteristic of runtime exceptions is that the Java compiler will not check it. That is to say, when this type of exception may occur in the program, it is useless even if it is not captured with a try-catch statement. The throws clause declares that it will be thrown, and it will compile.
Non-runtime exception (compilation exception): From the perspective of program syntax, it is an exception that must be handled. If it is not handled, the program will not be compiled. Such as IOException
, SQLException
, etc., as well as user-defined Exceptions, but generally no checked exceptions are customized.
In fact: RuntimeException, its subclasses and errors (Error) do not have to be caught or thrown.
Recommended tutorial: java introductory tutorial
The above is the detailed content of What is an exception that is not thrown in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.