Simple exception rules

Source: Internet
Author: User

Suddenly, I was interested in exceptions. I ran a very simple program and found a problem that I ignored all the time. Although it didn't make any sense for this question, it was very important, the consequence would be terrible if we didn't figure out these things when using jdbc, io, and so on.

Next, let's talk about the concept of why I am wrong for the program. I just want to remind myself of it.

 
Package com. zhao. practice801;

02 /**

03 * Basic Study on exceptions

04 * <A class = referer href = "http://my.oschina.net/arthor" target = _ blank minmax_bound = "true"> @ author </A> Administrator

05 *

06 */

07 public class TestException {

08 public static void main (String [] args ){

09 String str = null;

10 // obtain the string length

11 int length = 0;

12 try {

13 length = str. length ();

14 System. out. println ();

15} catch (Exception e ){

16 e. printStackTrace ();

17}

18 System. out. println ("program exited ");

19}

20}


I always thought that if an exception occurs, I would not execute the following statement. I found the error. It is only a method body and will not overwrite the Code except the method body. This is the result of the program.

Exit Program

2 java. lang. NullPointerException

3 at com. zhao. practice801.TestException. main (TestException. java: 13)

,

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.