14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Designing Exception Classes 7.2

maybe it’s best to declare a static exception class in the signature so that potential

calling programs are aware of the danger.

Is the error

more than

1% likely?

No

Can the routine

handle it locally?

Yes

No

Yes

CX_NO_CHECK

Can the routine

handle it locally?

Are you

Yes

barking mad?

Yes CX_DYNAMIC_CHECK

No

No

Will this routine

be used by

multiple

programs?

Yes

CX_STATIC_CHECK

No

CX_NO_CHECK

Figure 7.1 Exception Class Decision Tree

7.2 Designing Exception Classes

Java programmers often say that everything is an object. When it comes to exception

classes, they’re right: exception cl asses are classes that represent an unexpected

situation, and the objects they create are instances of one specific error situation

of this type. Realistically, you’ll have to design your own custom exception

classes so that you can have application-specific attributes. (There are a lot of standard

SAP exception classes, but they tend to have names like CX_JAPANESE_MICE_

RACING_ERROR, which is a bit too specific for general reuse.)

There are several steps in the process of designing an exception class, which can

be described as followed:

263

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

Saved successfully!

Ooh no, something went wrong!