1 Inheritance Diagram
2 Specific explanations
C + + Standard library Exception class inheritance hierarchy in the root class is exception, which is defined in the exception header file, it is the C + + standard library all functions throw
cause the system to crash if it is ignored. Obviously this is not the expected result. Therefore, how can we handle and remedy errors during operation? Java provides an exception mechanism to handle errors during program running. Through the exception mechanism, we can better improve program robustness.
Exceptions are processed as objects in
Java exception and exception handling, Java Exception Handling
1. What is an exception?In short, it is because the program runs a problem, but you can try... And catch, and then the program continues to run.In
All exception types are subclasses of the Throwable class, which contains the exception class and the error class, and exception also includes checked exception and unchecked exception.
ignored during compilation.
Runtime exception:Running exceptions may be avoided by programmers. In contrast to checking exceptions, runtime exceptions can be ignored during compilation.
Error:The error is not an exception, but an issue that is out of programmer control. Errors are usually ignored in the code. For example, when the stack overflows, an error occurs and they cannot be checked during compilation.
.
Note: Regardless of whether the program code block is in the try block or even the code in the Catch block, an exception is generated automatically whenever an exception occurs when the code block is executed. If the program does not define any catch blocks for this code, the Java Runtime Environment cannot find a catch block to handle the
, but not all errors are exceptions, and errors can sometimes be avoided. For example, if your code is missing a semicolon, then the result is that the hint is error java.lang.Error; If you use System.out.println (11/0), then you're using 0 as a divisor, Throws a Java.lang.ArithmeticException exception.
Some exceptions need to be handled, while others do not require capture processing, which is described in detail later.
The sky is unpredictable, peop
Introduction to exceptions and errors in java learning, exception capturing, exception throwing, custom exceptions, finally keywords (small records in java learning), and finally keywords
Introduction to exceptions and errors in java learning,
Object-oriented Exception Handling: an in-depth understanding of java exception handling mechanism, and an in-depth understanding of Exception Handling
What is an exception?
An exception is a description of the problem. It encapsu
program is running, we call it exception handling when we catch the exception and try to get the program to continue running. Exception handling changes the execution process of the program, that is, when the program is abnormal, that is, a plan fails, we execute the standby B plan, so that the business continues. which exceptions we can handle some of the run-t
Exception ($error)
} catch (Exception $e) {
echo $e->getmessage ();
}
2, we can expand this class, convenient for our use
Copy CodeThe code is as follows:
Class MyException extends Exception
{
Redefine the constructor to make the message a property that must be specified
In Java, all exceptions have a common ancestor throwable (can be thrown). Throwable specifies the commonality of any problems that can be transmitted through a Java application by using the exception propagation mechanism available in the code.
Throwable has two important subclasses: Exception (
{
$error = ' my error! ';
throw new Exception ($error)
catch (Exception $e) {
echo $e->getmessage ();
}
2, we can extend this class, to facilitate our use
Copy Code code as follows:
Class MyException extends Exception
{
Redefine the con
Java: Exception Handling, java Exception HandlingContent:
Exception description
Exception Handling
Assertions
Start Date:Exception:
An exception is an error that occurs during
overwritten, and classes cannot be inherited.
(2) finally is a keyword in exception handling, indicating that the code in finally {} must be executed.
(3) finalize is a method of the Object class. This method is called during garbage collection.
6. If there is a return statement in try (), will the code in finally {} be executed? When will it be executed, before or after return?
I wrote a code and tested i
a top-level exception handler to handle the missing error. It is easy to create a custom exception handler by creating a custom Exception class. We simply created a special class that called its function when an exception occurre
-> getMessage () from this exception object to output error messages from this exception.
However, to follow the "each throw must correspond to a catch" principle, you can set a top-level exception processor to handle missed errors. It is very easy to create a custom Exception handler for the custom
/*** Return Whether the given Throwable is a checked exception: * That's, neither a runtimeexception nor an ERR Or. * @paramex the Throwable to check *@returnwhether the throwable is a checked exception *@seejava.lang.Exception *@seejava.lang.RuntimeException *@seeJava.lang.Error*/ Public Static Booleanischeckedexception (Throwable ex) {return! (exinstanceofRuntimeException | | ExinstanceofError); }
-> getMessage () from this exception object to output error messages from this exception.
However, to follow the "each throw must correspond to a catch" principle, you can set a top-level exception processor to handle missed errors. It is very easy to create a custom Exception handler for the custom
Java tutorial translation Sequence Java Introduction Build a JSE development environment-install JDK and eclipse Language basics Java Hello World Program Analysis Variable Java Variables Java Native type Conversion of Java
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.