Java Fundamentals Secondary Learning-fourth Chapter exception

Source: Internet
Author: User
Tags try catch

Fourth Chapter exception handling time: April 26, 2017 11:16:39~2017 April 26 11:28:58 chapters: 04 Chapters _01 04 Chapters _02 Festival Video Length: 20:46+01:16 content: The concept of exceptions experience:Java Exceptions are a mechanism provided by Java for handling errors in programsSome exception events that occur during the actual run (E.G. except 0 overflow, array out of bounds, file to be read does not exist)a well-designed program should provide a way to handle these errors when an exception occurs, so that the program does not block or produce unpredictable results due to the occurrence of an exception When an exception event occurs during the execution of a Java program, an object of the exception class can be generated that encapsulates the information of the exception event and is presented to the Java runtime system, a process called throw (throw) exception When the Java runtime system receives an exception object, it looks for code that can handle the exception and hands the current exception object to its processing, a process known as Catch (catch) Exception.  

  time: April 26, 2017 11:29:02~2017 April 26 11:32:52 Chapters: Chapter 04 _03 Video Length: 19:47 content: Classification of exceptionsexperience:throwable-->error, ExceptionError--hard to handle called errorException-->runtimeexception and other ExceptionRuntimeException often out of exception can not be capturedadditional exception must be captured (usually throws)like IOException or Something.Image 

   time: April 26, 2017 11:33:03~2017 April 26 14:38:31 Chapters: Chapter 04 _05 Video Length: s9:29 Content: finally Statementexperience:try{//code that may appear abnormal}you can follow one or more catch in the backeach catch snippet declares a specific type of exception that can be handled and provides a way to handle it

  Finally the statement is always executed a simple test of the condition of this sentence separately tested when heap memory overflow, stack memory overflow and system.exit () statement There are all kinds of return cases, finally the execution of the situation the first kind of heap overflow

 Print exception before output finally statement overflow of the second stack

 output finally statement and print exception first This is the case for both of thesetry{by constantly adding things to the heap or stack to make the memory overflow.}finally{System.out.println (".....")} and then, If you make a little change,try{by constantly adding things to the heap or stack to make the memory overflow.}finally{Add a statement to the memorySystem.out.println (".....")} 

and it doesn't output.but it actually went into the finally, just forced the virtual machine off.  the Third Kind of system.exit (0) or-1do not enter the finally statement the fourth kind about returnThere's a return in the try and finally no, That's it.Debug executes return after running to the return statementand then into finally .finally returns the return resultwhich meansThe Finally module statement is positioned before returning return after executing a return If there is return in finally, the return statement in the try or catch is directly Overwritten.  thus concludes That: 1 without terminating the jvm, the code in the finally is bound to Execute. the position of the 2.finally module statement is before returning a return after executing a return   If there is return in finally, the return statement in the try or catch is directly Overwritten.   time: April 26, 2017 14:38:31~2017 April 26 14:50:05 Chapters: Chapter 04 _06 Video Length: 12:57 Content: declaring a method throws an exceptionexperience:throws Exceptionthrows an exception method call can continue to throwBut the final step must be captured (not Runtimeexception) of course it can be thrown in the main method but not Recommended. ultimately, It's going to be Captured.otherwise, You don't know what 's going wrong.processing can not handle the outward throw 

   time: April 26, 2017 14:50:37~2017 April 26 15:07:38 Chapters: Chapter 04 _07 video length: 12:01 +1:28 Content: Other issues with exceptionsexperience:when the catch is repeatedfollow the first catch small exception and catch the big exceptionotherwise the compilation will not pass (because it has been captured)There's No such restriction on Juxtaposition. about custom Exceptions1. Declaring your own exception class by inheriting the exception class2. Generate an instance of the custom exception in the appropriate location of the method and throw it with the throw statement3. Declare the exception that may be thrown by the method in the declaration section of the method with the throws statement 

 Note: The overriding method needs to throw an exception that is consistent with the type of exception thrown or does not throw summary of 5 keyword Try Catch finally throw throws

Java Fundamentals Secondary Learning-fourth Chapter exception

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.