CSE 8B Lecture 16: Lecture 16: Wrap up

28 views2 pages

Document Summary

Exceptions and generics in java: unchecked exceptions, do not have to put inside a try-catch block, checked exceptions, must put inside try-catch block, handling exceptions. If try-catch block has throw exception method header must have throws exception: throws exception back to caller finally block always runs regardless of an exception being thrown. If code in a catch block runs finally block runs, then code crashes if catch block throw. Exception: catch specific exceptions first, then generic ones. // compile error: cannot create objects from formal types, cannot create arrays of formal types, cannot use as an argument to instanceof public static > e findmax (e[] list) { // e must implement comparable interface and override compareto() // non-primitive data types like string already has compareto() implemented. E maxelement = list[0]; for(int i = 0; i < list. length; i++) { if(maxelement. compareto(list[i])<0) { // maxelement is less than list[i] (smaller) maxelement = list[i]; return maxelement;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions