OO Programming with Java


Error handling

  1. Finally, the main program has to take care of possible exceptions by the way of the try_catch statement:
try {
  bookstore.buy("Core Java", 30);
} catch (UnavailableException e) {
  e.printStackTrace();
}

Running the program will conduce to the exception:

chap4.UnavailableException
	at hello/chap4.Catalog.buy(Catalog.java:22)
	at hello/chap4.Catalog.main(Catalog.java:35)

3 - 12