Java Basics Learn Java exceptions

Source: Internet
Author: User
Tags throwable

1:unchecked Exception (i.e. runtime exception) VS Check Exception (non-runtime exception)

2: Run-time exception VS non-run-time exception?

Non-runtime Exceptions: The claim captures that must be displayed in code are either placed in the Try{}catch () {} block or declared throws on the method to throw the exception, and the type belongs to the exception class and its subclasses .

Run-time exception: do not need to be specifically stated , the General runtime exception is the virtual machine problems will be reported, such as you write a dead loop caused by memory, or the run-time exception is the RuntimeException class and its subclasses, such as Nullpointerexcetpion, indexoutofboundsexcrtiption, etc., the program can not be captured. It is usually caused by logic and should be avoided as much as possible.

R The untimeexception class is a subclass of the exception class, which is called a run-time exception, and all runtime exceptions in Java are inherited directly or indirectly from the RuntimeException class.

  Exceptions in Java that inherit from exception and do not inherit from the RuntimeException class are non-runtime exceptions .

3: What is abnormal loss?

 The old exception is lost when code that handles the exception throws a new exception after the exception is thrown.

4: Two ways of exception handling?

   Capture processing with try {} catch{} finally {}, throws excepltion after the function, throws an exception, and the function internal throw new Exception ().

5: How do I customize exceptions?

 Inherit exception or its subclasses (such as RuntimeException).

6:try statement block has return, will execute finally? If there is a return before executing try{}, will the finally execute?

  a return in T Ry will also execute the code in finally, and if it is sytem.exit (0), the finally is not performed ;

If there is a return before the try, finally is not executed.

An exception match in 7:catch?

The base class catches the derived class exception . Catch, it matches the derived class first, and then the base class.

The difference between 8:throwable, Error, Exception, runtimeexception?

(1) TheThrowable class is a superclass of all errors or exceptions in the Java language. Its two sub-classes are error and exception;

(2) error is a subclass of Throwable that indicates a serious problem that a reasonable application should not attempt to capture. Most of these errors are abnormal conditions;

(3) The exception class and its subclasses are a form of throwable, which points out the conditions that a reasonable application wants to capture;

(4) RuntimeException is a superclass of exceptions that may be thrown during the normal operation of a Java virtual machine.

Any subclass of RuntimeException that may have been thrown but not captured during the execution of the method does not need to be declared in the throws clause. It is a subclass of exception;

Java Basics Learn Java exceptions

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.