1. If there is a throws exception inside the method declaration name, the method body can not throw an exception. Because the exception description can be included in the method declaration, it is not actually thrown! The advantage of this is that you take a position for the exception before you can throw the exception without modifying the existing code. This ability is important when defining abstract base classes and interfaces so that derived classes or interface implementation classes can throw these pre-declared exceptions.
2. Why is there no throws in the method declaration, but the method body throws an exception? Exceptions inherited from RuntimeException can be thrown without exception description throws! For runtime exceptions (also known as non-checked exceptions unchecked exception), the compiler does not require an exception description. 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. The reason for this is that RuntimeException represents a programming error.
3. Runtime exceptions are automatically thrown by Java virtual machines!
1. Exception Handling Basics 1.1 System.out.println is a high price. Calling SYSTEM.OUT.PRINTLN can reduce system throughput. 1.2 Do not use the exception Printstacktrace () method in the production environment. Printstacktrace The call stack is printed to the console by default, and accessing the console in a production environment is unrealistic. 2. Exception Handling Fundamentals 2.1 Do not catch the exception if you cannot handle the exception. 2.2 If you want to capture it, you should capture it near the source of the anomaly. 2.3 Don't swallow the exception you caught. * (is the catch exception, but do nothing) 2.4 unless you want to re-throw the exception, log it up. 2.5 When an exception is repackaged and then re-thrown, do not print the STATCK trace. 2.6 with a custom exception class, do not throw java.lang.Exception every time you need to throw an exception. The caller of the method can know what exceptions need to be handled by throws-so it is self-describing. 2.7 If you write business logic, the system should throw a non-checked exception for errors that the end user cannot fix (unchecked exception) If you write a third-party package to other developers, use the exception (checked exception) you want to check for uncorrectable errors. 2.8 Never make it uncomfortable to write throws statements without declaring the exceptions you need to check. 2.9 Application-level errors or uncorrectable system exceptions are thrown with non-checked exceptions (unchecked exception). * (note is error, meaning cannot be repaired, such as configuration file wrong 2.10 Organize your approach according to the granularity of the anomaly the three principles for effective handling of Java exceptions http://www.importnew.com/1701.html
Other reference articles:
http://klyuan.iteye.com/blog/72170
http://blog.csdn.net/luqin1988/article/details/7970792
http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html the corresponding translation, not very accurate: http://blog.sciencenet.cn/ Blog-252888-761119.html
http://www.oschina.net/question/92866_15634
Http://www.importnew.com/1701.html
http://sunflowers.iteye.com/blog/767175
Exception handling in Java: When to throw an exception and when to catch it?