14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Types of Exception Classes 7.1

which department is best able to deal wi th this situation: perhaps the police,

the fishmonger, or the fire department. Likewise, your program has to make a

similar decision—so this chapter starts by discussing the different types of

exception classes, which allow you to ch oose the appropriate part of the program

in which to deal with a raised error signal (Section 7.1).

왘 Once you notice your house is on fire, you phone 999 (United Kingdom) or 911

(United States) to report the situation and tell them your address. Then, the fire

department comes around and puts out th e fire. To express this in programming

terms, you need to design an exception class to respond to specific types

of situations and store pertinent information for onward transmission to whatever

will deal with the problem—and then you have to actually deal with that

problem. This is what exception classes are all about (Section 7.2).

왘 After the event, when you make an in surance claim, the insurance company

will investigate the cause of the blaze. Did you accidently set your house on fire

yourself? Did you hire a cook to prepare a banquet, and the cook accidently set

the house on fire? In programming term s, the concept of design by contract

comes into play here. This means determining if the cause of the error is at the

start or end of each routine (Section 7.3).

Exception Terminology

This chapter uses five phrases, all with the word exception in them. To make sure you’re

not confused, keep the following in mind:

왘 An exception is an unexpected situation. This is a real world event.

왘 Exception handling is how a program recognizes and reacts to such an event.

왘 Exception classes are one possible way to implement exception handling; as you

should already have guessed from the chapter title, this is the focus of the chapter.

왘 Raising an exception is the process of creating an instance of an exception class during

the course of exception handling.

왘 An exception object is the instance created when raising an exception.

7.1 Types of Exception Classes

The first decision you’ll have to make when designing exception classes is what

type you need. The type you choose will determine things like whether you handle

the error locally or remotely and where you can put handling code. With that

257

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!