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.

Designing Exception Classes 7.2

Meanwhile, back at the ranch, the BEFORE UNWIND statement makes sure that the

local variables of the called routine DO_NOT_KNOW are preserved so that they are

still available when processing restarts after the error has been fixed. If you try to

do a RESUME statement without the BEFORE UNWIND, then you get a syntax error. (A

CLEANUP block isn’t needed in this situation, because it alters the state of the variables—which

is exactly what you’re trying to avoid, which is why it doesn’t get

called.)

*&--------------------------------------------------------------*

*& Form RESUMABLE

*&--------------------------------------------------------------*

* Routine that knows what to do with incorrect data

*---------------------------------------------------------------*

FORM resumable .

gf_data_is_rubbish = abap_true.

TRY.

PERFORM do_not_know.

CATCH BEFORE UNWIND cx_ai_application_fault.

"Repair the data using special knowledge

"only this level knows

IF gf_data_is_rubbish = abap_true.

gf_data_is_rubbish = abap_false.

ENDIF.

RESUME.

ENDTRY.

ENDFORM. " RESUMABLE

*&--------------------------------------------------------------*

*& Form DO_NOT_KNOW

*&--------------------------------------------------------------*

* This routine does not know how to repair data

*---------------------------------------------------------------*

FORM do_not_know RAISING resumable(cx_ai_application_fault).

TRY.

MESSAGE 'I am executed before the execption' TYPE 'I'.

IF gf_data_is_rubbish = abap_true.

RAISE RESUMABLE EXCEPTION TYPE cx_ai_application_fault.

ENDIF.

MESSAGE 'I am executed after the exception' TYPE 'I'.

CATCH ycx_monster_exception.

273

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

Saved successfully!

Ooh no, something went wrong!