Exceptions
Java allows us to create our own exception classes, but before creating it, ask yourself if the exception class that comes with the JDK really doesn't meet your needs. If so, we should use the exception class that comes with the JDK. Because when other people read the code, they are usually familiar with the JDK's exception system, you write the exception class will be very unfamiliar. If we need to create a new exception class ourselves, we should consider whether the exception class we write should inherit exception or RuntimeException. In general, they inherit the latter.
Recommendations for exception handling:
There is a few additional items to keep on mind when working with throws clauses and throw statements:
1.You can append a throws clause to a constructor and throw a exception from the constructor when something goes wrong wh Ile the constructor is executing. The resulting object won't be created.
2.When An exception was thrown out of a application ' s main () method,the virtual machine terminates the application and calls the exception ' s Printstacktrace () method to print, to the console, the sequence of nested method calls this was Awaiting completion when the exception was thrown.
3.If A superclass method declares a throws clause, the overriding subclass method does not having to declare a throws clause . However,if It does declare a throws clause, the clause must not include the names of exception classes that is not also I Ncluded in the superclass method ' s throws clause.
4.A checked Exception class name does not need to appear in A throws clause when the name of its superclass appears.
5.The compiler reports an error when a method throws a checked exception and does not also handle the exception or list th E exception in its throws clause.
6.Do not include the names of unchecked exception classes in a throws clause. These names is not required because such exceptions should never occur. Furthermore, they only clutter source Code,and possibly confuse someone who's trying to understand that code.
7.You can declare a checked exception class name in a method ' s throws clause without throwing an instance of this class fr Om the method. Perhaps the method has yet to be fully coded.
for the 2nd, the younger brother understand is not very in place, have understanding of eldest brother also trouble pointing under
Learn Learning Java for Android-exceptions