Thursday, September 2, 2010

Programming the difference between exceptions and errors

Exception catch, such as try-catch blocks is a test run when we compile the compiler encounters try-catch blocks, then it will test run the next, that is, the code first checks whether the error, if error under catch to handle errors returned the wrong reasons then we can give you to determine based on erroneous, such as we see a Scanner input = new ...
Abnormalities, such as try-catch blocks to capture is the test run
When we compile the compiler in the device if you encounter the words try-catch blocks will be test run Xia, also code Zhong Jiu Shi Jian Cha is the first error occurs, if there is an error on Genju catch Quchu Li error Fanhui error of the Yuan Yin Ji you and Women on to judge according to the error, such as we see a Scanner input = new Scanner (System.in);


But if there is no try-catch, then add it, the compiler will not catch the error to detect.

Such as

Scanner input = new Scanner (System.in);

int x = input.nextInt ();

This time we enter a string "I love you"

This will return an error when

If we are so

try (

int x = input.nextInt (); 
) Catch (Exception ex) (

/ / If you enter non-numerical code on the implementation of here

System.out.println (ex.getMessage); 
)

No comments:

Post a Comment