Chapter 6: Inheritance and Abstract Classes Chapter Topics 6.1 ...
Chapter 6: Inheritance and Abstract Classes Chapter Topics 6.1 ...
Chapter 6: Inheritance and Abstract Classes Chapter Topics 6.1 ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
CS151 Object-Oriented Design<br />
Dr. Kim<br />
public static void main(String<br />
[] args) throws IOException<br />
{ m1(); }<br />
JVM<br />
public void m1() throws<br />
IOException<br />
public void m2()<br />
throws IOException<br />
{ BufferReader in = …<br />
…<br />
}<br />
= in.readLine()<br />
Method call<br />
When an exception is<br />
thrown:<br />
6.8.4 Defining Exception <strong>Classes</strong><br />
• By convention, most new exception types extend Exception,a subclass of Throwable.<br />
• Exceptions are primarily checked exceptions. A unchecked exception class should extend<br />
RuntimeException .<br />
• Should provide two constructors: a default constructor <strong>and</strong> a constructor with a string<br />
parameter that signifies the reason for the exception.<br />
public class IllegalFormatException extends Exception<br />
{<br />
public IllegalFormatException() {}<br />
public IllegalFormatException(String reason)<br />
{ super(reason); }<br />
}<br />
• The above code defines a checked exception class which inherits from the Exception<br />
class but not from RuntimeException.<br />
37