Interrupts and restores of Java exceptions

Source: Internet
Author: User

Interrupt: Throws an instance of an exception class and terminates execution of the existing program;
Recovery: Instead of throwing an instance of an exception class, call a method to resolve the problem or resolve the problem in place.

In Java, for the client programmers who want to invoke the method, we have to inform them that they may "throw" the violation in their own way. This is a polite approach that only allows the client programmer to know exactly what code to write to capture all potential violations.

Catch (Exception e) {System.out.println ("Caught an Exception");

This code captures any violation, so it is best to place it at the end of the controller list when it is actually used, to prevent any special offending controllers that follow it from invalidating. For all the offending classes commonly used by programmers, because the exception class is their basis, we don't get too much information about the violation, but we can call the method from its underlying class Throwable:

String GetMessage ()

Get the detailed message.

String toString ()

Returns a brief description of the Throwable, including a detailed message, if any.

void printstacktrace () void printstacktrace (printstream)

Prints the call stack path for Throwable and Throwable. The call stack shows the order of the method calls that take us to the offending place.

The first version prints out the standard error, and the second prints out our selection process. If you are working under Windows, you cannot redirect standard errors. Therefore, we generally prefer to use the second version and send the results to System.out so that the output can be redirected to any path we want.

Interrupts and restores of 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.