Class Notes (834,966)
Canada (508,836)
CSC207H1 (40)
Lecture

oct17c.docx

1 Page
72 Views
Unlock Document

Department
Computer Science
Course
CSC207H1
Professor
Diane Horton
Semester
Fall

Description
OCTOBER 17  Why was that code bad? o The situation that the exception reports is not exceptional o It's uncharacteristic. Real uses of exceptions aren't local  throw and catch aren't generally in the same block of code.  Cascading catches o Much like an if with a series of else if clauses, a try can have a series of catch clauses. o After the last catch clause, you can have a clause: finally { ... } o But finally is not like a last else on an if statement:  The finally clause is always executed, whether an exception was thrown or not, and whether or not the thrown exception was caught.  Example of a good use for this: close open files as a clean-up step. o Example of Muitple Catches: suppose ExSup is the parent of ExSubA and ExSubB 1. try { 2. ... 3. } catch (ExSubA e) { 4. // We do this if an ExSubA is thrown. 5. } catch (ExSup e) { 6. // We do this if any ExSup that's? Not an ExSubA is thrown. 7. } catch (ExSubB e) { 8. // We never do this, even if an ExSubB is thrown. 9. } finally { 10. // We always do this, even if no exception is thrown. 11. }  ex. o TooLargeException.java 1. package ExceptionDemos; 2. public class TooLargeException extends Exception { 3. } o Throwing.java 1. package ExceptionDemos; 2. 3. public class Throwing { 4. private static double m4(double k) throws TooLargeException { 5. System.out.println("Inside m4"); 6. if (k < 1000) { 7. return k *
More Less

Related notes for CSC207H1

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit