COMP 202 Lecture Notes - Lecture 32: Exception Handling, Hard Disk Drive

61 views6 pages
jc123 and 40170 others unlocked
COMP 202 Full Course Notes
100
COMP 202 Full Course Notes
Verified Note
100 documents

Document Summary

Exceptions are some event that happens during the execution of the program that disrupts the normal flow of instructions. This happens when you ask the computer to do something that doesn"t make sense. Eg, dividing by 0 or accessing a value in an array at an index that doesn"t exist. In order to prevent our code from crashing at runtime, instead of using if statements/blocks to catch all the possible things to go wrong and have a condition for each, you can use these try-catch block s. You can have as many catch block s as you want. This makes sense to do if you want to do something different depending on what kind of exception happens. If you get a nullpointerexception, you might want to do something different than if you get an arithmeticexception. It will always happen when the try block exits. You can have a finally with just a try -- you don"t need a catch in-between.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents