Experience 24 -- try {} catch (){}

Source: Internet
Author: User

Capture exceptions.

Try {}

Catch (exception E)

{Throw new exception ("exception found ");}

1. We recommend that you capture exceptions when writing a piece of code. After capturing a piece of content, you can submit it to the outer layer or perform your own processing.

Such as writing data to a database, writing logs, and writing text. Or restart a program.

2. We recommend that you capture the entire code one by one, so that you can clearly know where the error is and facilitate debugging.

3. You can also customize the exception class to handle the exception.

4. When writing code, capture abnormal statements instead of being lazy.

5. Exceptions can be captured in database operations, writing files, Web requests, and other related program segments.

6. Overall exception Capture: when multiple exceptions are caught in the code, you can capture the code again to implement overall control.


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.