[Java advanced knowledge from zero point (a)] Exception and Error

  1. Exception 和 Error
    1. Exception and Error are inherited Throwable class in java, only inherited the Throwable class can use throw throw, or cath capture;
    2. The Exception means unreasonable java runtime may occur, and the program does not quit unexpectedly when the event. Exception which can be divided into abnormalities, non abnormalities. Abnormalities can be displayed captured, or throw, catch exceptions do not need to check the non-displayed, or throw;
    3. Error intended to run as a java error occurs, the program will make the event most of the abnormal exit, so that the program can not be used;
  2. Knowledge extension
    1. Try not capture similar Exception such a common anomaly, but should catch specific exceptions.
    2. Do not swallow the exception information.
    3. Do not use printStackTrace (), this method sets the system information to the standard error (standard error stream), the output is difficult to determine where in the end, the best is output to the system log.
  3. Problem Set:
    1. NoClassDefFoundError and the difference between ClassNotFoundException;
      NoClassDefFoundError is an error (Error), and ClassNOtFoundException is an exception in Java to handle errors and exceptions are different, we can resume the program from the exception but the program should not attempt to recover from errors .

      ClassNotFoundException mainly causes:
      the Java reflection mode supports dynamically loading classes at runtime, for example using the method Class.forName dynamically loaded class, the class name may be passed as a parameter to the method described above so that the specified class is loaded into the JVM memory if the class is not found in the class path, then the time will be thrown at runtime ClassNotFoundException exception.
      To solve this problem the need to ensure the required class, along with its dependent packages present in the class path, a common problem is that the class name clerical error.
      There is another reason ClassNotFoundException led to is this: When a class has a class loader loads into memory, and this time another class loader and try to dynamically load the class from the same package. By controlling the dynamic class loading process, can be avoided from happening.

      The reason is that NoClassDefFoundError produce:
      the definition or if the JVM ClassLoader instance tries to load (can be called by the normal method, it may use new to create a new object) class when they can not find the class. To find a class at compile time is there, but can not find the time to run. This time it will lead to NoClassDefFoundError.
      The cause of the problem might be missing some of the packaging process class, jar or bag is damaged or tampered with. The solution to this problem is to find those classes but not in the class path at runtime during development exists in the class path.

Guess you like

Origin www.cnblogs.com/xiong233/p/10942914.html