Java entry note 5

xiaoxiao2021-03-06  36

1. The basic structure of the basic structural exception handling of abnormal processing is as follows: try {someReallyExceptionalMethod ();} catch (nullpointerexception n) {// a subsclass of runtimeException........................................................................................................................................... Subclass of exception... THROWABLE............................................................. There are two subclasses: Error class and Exception class, an instance of an Error class is an internal error in the Java operating environment. These errors are very small and very fatal. We cannot or rarely process these errors, or capture these errors. . The Exception class can be divided into two categories, one is the runtime Exceptions (Runtime Excetions) such as SecurityException, ArrayIndexoutofbounds, NullPointerexception, etc .; the other is except for EOFEXCeption, etc. In the Exception class hierarchy, the more the upper Exception class, the more general, and the more the following Exception is more targeted. In most Exception classes are part in the java.lang package, others exist in other packages. Generally, in the TRY code, capture possible errors in the Catch, generally starting from a specific error, always throwable, and if you get into the code that needs to be processed, such as Exit the cycle, release resources, and so on. 1.2 Declaring Methods Methods Methods You can add keyword throws when declaring methods, to illustrate that this method may generate a certain or certain exception, such as: Public Boolean myothermethod (int x, int y) throws Anexception, Anotherexeption, AthirdException {...} With this declaration, other places where this method uses this method is preferably used to process the exception specified by this method. 1.3 Creating your own anomaly class Yourself-defined anomaly class inherited from other anomaly classes, it is best to find a close anomaly class to inherit, such as defining an exception class of file format errors, it is best to inherit from IOException.

转载请注明原文地址:https://www.9cbs.com/read-55647.html

New Post(0)