java--Standard Exceptions

Source: Internet
Author: User
Tags throw exception

Throwable this Java class is used to represent any class that can be thrown as an exception, Throwable can be divided into two types, error is used to denote compile-time and system error, and exception is the basic type that can be thrown.

1, RuntimeException

 Public class Tree1 {        publicstaticvoid  f () {        throwNew runtimeexception ();    }          Public Static void g () {            f ();    }          Public Static void Main (string[] args) {            g ();    }}

Output Result:

Exception in thread "main" java.lang.RuntimeException at    tree1.f (Tree1.java:6) at    tree1.g ( Tree1.java:at    tree1.main (tree1.java:14)

General exceptions need to be treated like this,

       Try {            ///may throw exception code         }        catch(Type1 id1) {             // handling code for TYPE1 type exceptions         }        catch(Type2 id2) {            ////handle type2 Type exception code        }

RuntimeException is not a generic exception, it is a runtime exception that is automatically thrown by the Java Virtual machine and will be automatically captured.

However: exceptions of type runtimeexception (and its subclasses) can only be ignored in code, and the handling of other types of exceptions is enforced by the compiler, because in fact runtimeexception represents a programming error,

java--Standard 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.