Classification of exceptions1. Non-runtime exception (Checked Exception)All classes in Java that inherit from exception but not inherit from RuntimeException are non-runtime exceptions.2. Runtime exception (runtime exception/unchecked Exception)The RuntimeException class inherits directly from the exception class, called a run-time exception. All run-time exceptions
, please handle");//here is the exception object, so the exception//parameter can pass a getmessage come inSystem.out.println (T.tostring ());//java.lang.Throwable: This is an exception, please handleSystem.out.println (T.getmessage ());//This is an exception, please handleT.printstacktrace ();//Print an unusual stack of memory information }}Error Error: Errors are generally problems caused by Java virtual machines or hardware, called errors. So we
, first grabbed the throwable this all exceptions, including error (the following will introduce the anomaly system). The code inside hides the problem, just print a line of logs, and let the program can continue to go backward, the uncertainty and risk are very large, which also greatly affect the robustness of the code.3. The principle of a clear hierarchy of disruptive structures and a single responsibility is a major impediment to system expansion
specification for the first introduction of exceptions, but Java is mandatory " Check for exceptions " ( Checked Exception ) Specification of the only mainstream languageAuthor :: old Wow's paw attilax Ayron, email:[email protected]Reprint please indicate source: Http://blog.csdn.net/attilax2. Throwing an exception into a catch clause with a throw is basically t
Java: how to correctly use exceptionsOverview:
The exception mechanism in Java is a good thing. However, good things must be correctly used, otherwise it will make us mistakenly understand it. It will be incorrectly used if it is incorrectly recognized. This becomes a vicious circle. This is not what we are willing to see. Don't think we can
guarantee that the function caller will necessarily detect the variable or test the error code. The resulting program will continue to run from the abnormal state it encounters, the exception is not captured, and the program terminates execution immediately.In the C program, we can use int setjmp (Jmp_buf env), and void longjmp (jmp_buf env, int value), these 2 functions to complete and exception handling acquaintances, but MSDN describes the
[Java Exceptions]The base class for all exceptions and errors in 1.java is throwable** throwable** error exception* (check-in exception) (Runtime exception) * * Exceptions in 2.java are divided into runtime
object (xxxexception)3. The statement after the program does not execute, automatically returns to the previous level method, and the previous method accepts the exception object for processing4. Treatment of the upper-level approach--the method has the ability to process (process in this method)--the method does not have the ability to process (continue to throw), if the current method is main, he throws the JVM, which causes the JVM to terminate the program's runHow the exception is handledTh
interface developers to modify the potential problems, re-release interface, this time we can choose unchecked Exception./*unchecked exception Need try-catch*/Sometimes in order to program does not crash, need to unchecked exception also try-catch, which depends on the interface source code must be familiar with, but because of the unchecked exception, the caller can not guide the program into the normal process, So even if Try-catch catches an exception, subsequent calls will continue to throw
execute"); Catch (ArithmeticException e) { System.out.println ("Exception handling:"); System.out.println (E.getmessage ()); } System.out.println ("code after Try...catch can be executed"); }3. Throw of the run-time exception Without processing, the exception can be thrown to the upper layer for processing by the upper layer. Public Static voidMain (string[] args) {Try{testnullpointerexception (); } Catch(NullPointerException e) {e.printstackt
was reminded by a colleague's remark. In fact, Himi on the Android side of the development compared to a lot less. The introduction of jars, I introduce problems caused by.Later I re-introduced Android-async-http-x.x.x.jar by the following steps to resolve:Right-click on the Android project under the Libs->import->general->file system->browse ...* This jar package is cocos2dx/cocos/platform/android/java/libs under the projectCheck Select Libs->finish
Java not caught exceptionBefore you learn to handle exceptions in a program, it's good to look at what happens if you don't deal with them. The following applet includes an expression that intentionally causes a 0 error to be removed.
Class Exc0 {public
static void Main (String args[]) {
int d = 0;
int a = 42/d;
}
}
When the Java runtime
(MyException e ){System. out. println ("data logic error ");System. out. println ("reason:" + e. getMessage ());}}}Public class MyException extends Exception {Private static final long serialVersionUID = 1L;Private String name;Public MyException (String name ){This. name = name;}Public String getMessage (){Return this. name;}}Then I will explain when to use it:If a system exception occurs, you do not need to do anything. You can a
Two types of exceptions are defined in Java
Checked exceptions:checked exceptions inherits from the exception class, calling client code that throws this exception API must handle the lead, otherwise it cannot be compiled, The exception is either caught by a catch clause or continues to be thrown through the throws clause. such as: SQLException
Unche
. printStackTrace (); prints abnormal stack memory information
Package study; public class star {public static void main (String [] args) {Throwable t = new Throwable ("this is an exception, please handle it "); // This is an exception object, so the exception // You can pass a getMessage to the System parameter. out. println (t. toString (); // java. lang. throwable: this is an exception. Handle System. out. println (t. getMessage (); // This is an
1.Java anomaly MechanismJava handles exceptions as objects, and defines a base class java.lang.Throwable as a superclass of all exceptions. Exceptions in Java fall into two main categories: Error errors and exception Exception,java
1.Java anomaly MechanismJava handles exceptions as objects, and defines a base class java.lang.Throwable as a superclass of all exceptions. Exceptions in Java fall into two main categories: Error errors and exception Exception,java
runtimeexception system includes wrong type conversions, array cross-border access, and attempts to access null pointers, and so on. The principle of dealing with runtimeexception is that if runtimeexception is present, it must be a programmer's fault. For example, You can avoid array out-of-bounds access exceptions by examining array subscripts and arrays boundaries.2.2.2.2 Other (IOException, etc.)Such exceptio
ExceptionException: An exception is an error that occurs while the Java program is running. Exception Origin: The problem is also a real life of a specific transaction, can also be described in the form of Java classes, and encapsulated into objects. In fact, Java is a description of the abnormal situation after the object. Throwable|--error Serious problems that
there is an exception, according to the exception prompt information for program modification. For example, null pointer exception nullpointexception, we can throw the message "xxx is empty" to locate the exception location, without the output stack information.What's the benefit of using a custom exception, let's look at the problem with custom exceptions:There is no doubt that we cannot expect the JVM (Java Virtual machine) to automatically throw a
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.