1 / 9

Chapter 11

Chapter 11. Risky Behavior . Overview. Handling Risky Code Exceptions Agreeing to Risk try/catch blocks finally block Declaring an Exception Handle or Declare law. Handling Risky Code. Risky code is code that may not work at Run Time

ulric
Download Presentation

Chapter 11

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 11 Risky Behavior

  2. Overview • Handling Risky Code • Exceptions • Agreeing to Risk • try/catch blocks • finally block • Declaring an Exception • Handle or Declare law

  3. Handling Risky Code • Risky code is code that may not work at Run Time • Lots of risky code is code that relies on outside resources • We deal with them in GUIs, Serial, File IO, and sound.

  4. Exceptions • In java, and exception is an object of type Exception • Since it is an object, we as apply standard Object methods to it as well as Exception Methods • Exceptions need to be 'caught' in Java

  5. Agreeing to Risk • Exceptions are going to occur • By using Java try/catch blocks you are acknowledging that exceptions can happen • This lets you deal with them rather than ignore them

  6. try/catch blocks • To catch and exception, use a try/catch block • Example

  7. finally block • try/block execute in order. The try is run, then as needed the catch is run. • At the end the finally block is run regardless of if an exception was returned or not.

  8. Declaring an Exception • What is you are writing the risky code? • You should warn people using your methods that you have an unhandled exception • This tells someone using your code that they have to deal with it, not you.

  9. Handle or Declare law

More Related