CMPSC 56 Chapter 11: HFJ Chapter 11 Exception Handling

46 views2 pages
8 Oct 2017
School
Course
Professor

Document Summary

To know if a method throws an exception, look for a throws clause in the method"s declaration. Try/catch block tells the compiler that you know an exception thing could happen in the method you"re calling and that you"re prepared to handle it. What you catch is also an object try { // try to recover public void takerisk() throws badexception { if (abandonallhope) { throw new badexception(); public void crossfingers() { try { anobject. takerisk(); If you throw an exception in your code, you must declare it using the throws keyword in your method declaration. If you call a method that throws an exception, you must acknowledge that you"re aware of the exception possibility i. e. wrap the call in a try/catch block. Most runtimeexceptions come from problems in code logic. The risky method succeeds, and the try block completes. The risky method throws an exception back to your calling method.

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

Related Questions