In a Java application, the exception handling mechanism is: Throw an exception, catch an exception.Throw exception : When a method throws an exception with an error, the method creates the exception object and delivers the runtime
Java exception description Java exception is a consistency mechanism provided by Java to identify and respond to errors. The Java exception mechanism separates the
First, Java exception Summary:
Exception is when the program is running abnormal operation
1. Origin of the anomaly:
Describe the problems in the real world through the form of Java classes and block them into objects
In fact, Java is the description of the object after
little bit? But it has a complete exception handling mechanism.
Outputstreamwriter out =...Java. SQL. Connection conn =...Try {Statement stat = conn. createstatement ();Resultset rs = stat.exe cutequery ("Select uid, name from user ");While (Rs. Next ()){Out. println ("ID:" + Rs. getstring ("uid") + ", name:" + Rs. getstring ("name "));}}Catch (sqlexception sqlex){Out. println ("Warning: incomple
recognizable return value. If the visitor does not synchronize and the object is accessed concurrently, select "recognizable return value" because there is a time interval between the methods that call the state test method and the state-related method. If other aspects are equal, select the "state test method", because there is better readability, and for improper use, the "state-related" method throws an exception to facilitate detection and correc
that may throw an exception} catch (Xxxexception e) {LOGGER.ERror (e); throw new RuntimeException (/* ERROR code */ErrorCode,/* Exception information */msg, E);} }} The same exception will be printed 2 times. If the hierarchy is a bit more complex, not to consider the system performance of the print log consumption, only in the
. Java.lang.IllegalAccessErrorillegal access error. This exception is thrown when an application attempts to access, modify, or invoke the domain (field) of a class or call its methods, but violate the visibility declaration of a domain or method. Java.lang.IncompatibleClassChangeErrorincompatible class change error. This exception is thrown when an incompatible change is made to the class definition on whi
, that is, the name of the parent class as the suffix of the subclass . All classes and objects in this system have a unique feature, which is parabolic. The embodiment of the parabolic: the class and object in this system can be manipulated by throws and throw two key words.Handling of exceptionsThere are two kinds of processing methods: 1, capturing, 2, throwing.1, Java provides a unique statement to handle.Try{The code that needs to be instrumented
The following is referenced from http://wiki.jikexueyuan.com/project/java/exceptions.html:An exception is a problem that occurs during the execution of a program. Causes of the exception include the following points:
Invalid data entered by user
User opens a file that cannot be found
The network connection has been lost or the JVM has exhausted m
Java. lang. ArrayIndexOutOfBoundsException exception analysis and solution, java. lang
Reference: http://blog.csdn.net/javaeeteacher/article/details/4485834
Http://bbs.csdn.net/topics/90298133
This is a very common exception. In terms of names, it is an array subscript out-of-bounds error. The solution is to check why
Java basics: exception capture sequence, java capture sequence
Reprinted with the source: jiq •'s technical Blog
Public voidtestException () {int a [] = {1, 2, 3}; int q = 0; try {for (int I = 0; I
* Point 1: Although ArithmeticException inherits from Exception, an ArithmeticException occurs.
* When the
code is called the exception handler, and the search begins with the method that occurred, then retrieves the call stack in reverse order of the calling method. When a corresponding processor is found, the runtime system passes the exception to the processor. An exception handler is required to properly filter the typ
Because C + + and Java have a lot of similarities, and there are a lot of subtle differences, so in the process of learning Java in the two languages to compare learning.1. Exception mechanism of C + +The process of handling exceptions in C + + is this: in the execution of the program exception, can not be processed in
rather than a particular action.Using throws is to illustrate that the current function throws an exception. In general cases, some of the functions you call throw some exceptions. But you do not want to handle it in the current context, and you can declare that the function throws the exception. So you don't have to try-catch it. When the exception occurs, the
Are you sure you want to read the exception information of Java ?, Read Java Information
The following error message is displayed:
java.lang.RuntimeException: level 2 exceptionat com.msh.demo.exceptionStack.Test.fun2(Test.java:17)at com.msh.demo.exceptionStack.Test.main(Test.java:24)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.Nati
In programs that do not have exception handling, if you want to avoid exceptions, you need to use a large number of judgment statements to match the error conditions you think of to catch errors that may occur in your program. However, this will inevitably lead to inefficient operation of the program.Java exception handling mechanism is easy to use, can customize the ex
This article emphatically introduced the Java exception choice and the use of some misunderstandings, I hope you can master the exception handling some of the points of attention and principles, pay attention to summary and induction. Only when the exception is handled, can we improve the basic literacy of the develope
Java Exception Handling Summary
Exception Handling is a very important aspect in programming and a major difficulty in programming. From C, you may already know how to use if... else... to control exceptions, it may be spontaneous. However, this kind of control exception is painful. If the same
} }}
Declaration of exception:
Throws is used to declare an exception, declaring a function that might occur. "When a throw is thrown in a function to throw an exception, the function header must declare the exception using throws"
Throw exception
above two ways is that when we throw the exception again, we lose the position where the first exception occurred, so we used Initcause to join the original exception and added "from division" to the exception information.
Interpretation of the
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.