1 / 10

SE-1021 Software Engineering II

Learn about exceptions in software engineering, including defining checked and unchecked exceptions, and how to handle problems using exceptions. Includes examples and best practices.

khargrove
Télécharger la présentation

SE-1021 Software Engineering II

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. SE-1021Software Engineering II • Week 7, Class 1 • Exceptions • Defining checked & unchecked • Handling problems with and without exceptions • Week 7, Friday: Exam II • (Examples from text)

  2. More Definitions • Checked exception – An exception that the compiler checks is handled • Unchecked exception – An exception that the compiler implicitly “throws” from a method if it is not handled explicitly. SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick

  3. General Principle • If a problem can be handled simply without exceptions, don’t use them • Otherwise, do use them SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick

  4. Problem 1a • Edit divideByZero/DivisionByZeroExample to keep asking for the denominator if it is zero SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick

  5. Problem 1b (aka 2a) • Next, handle wrong input • If either thing entered is wrong, loop back and ask for both numerator and denominator again SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick

  6. Problem 3a • Complete the NumerList example so that it prints the mean if the use behaves. • No need to handle user error SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick

  7. Problem 3b • If the user enters “q”, print “NaN” using double’s NaN value • Avoid catching the exception SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick

  8. Problem 3c • If the user enters something invalid (not q, not an integer), handle the problem. Do not re-prompt the user. • Fix the out-of-bounds exception if it occurs SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick

  9. To catch individually, what order? • Exception • IllegalArgumentException • IOException • NumberFormatException • RuntimeException SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick

  10. } catch ( ) { } catch ( ) { } catch ( ) { } catch ( ) { } catch ( ) { } SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick

More Related