You are on page 1of 8

Exceptions Handling

Plan

Error that you know how to porcess
directly

Process the error directly; you dont need to report it to user.

Example: you read a record and you got an error that it does not exists; in that case
and if it matches with your scenario, trap the error and if the error occurs you can
create a new record. You dont need to report the error to user.

Error that you cannot process at
your layer leel !

"he error needs to go up through layers, #e processed when it is possi#le or displayed to user. Example: you log on to a
system ia an $P%; you got an error &%nalid password'. "his error should go up to (% layer, and then #e displayed or ensure that
a new password is prompted.


)reate exception from *$P%+E"
"a#le

You are in the case, where you called an $P% that returns error
messages in a *$P%+E" "a#le. )reate the exception from the
*$P%+E" "a#le.
,$"$: lx-exception "YPE +E. "/ cx-sise-exception,
lt-#apiret "YPE #apiretta#,
ls-o#0ect-id "YPE etapi-o#0.
)$11 .(2)"%/2 3E)$""-/*4-P$+-5E"3
E6P/+"%25
is-key 7 ls-o#0ect-id
8 %9P/+"%25
8 et-params 7 et-parameter
"$*1E:
return 7 lt-#apiret.
%. lt-#apiret %: 2/" %2%"%$1.
lx-exception 7
cx-sise-exception7;create-from-#apiretta#< lt-#apiret =.
+$%:E E6)EP"%/2 lx-exception.
E2,%..

)reate a resuma#le exception

You are in the case, where you need to raise an exception #ut
you want let the possi#ility to let the process continue. %n that
case you hae to raise a resuma#le exception. /nce the
exception will #e catch the catcher will #e a#le to decide if he
wants or not to continue the process.

>$+2%25: %n order that resuma#le exception works it is ery


important that all exception in the entire way through the
layers #e flagged as &+esuma#le' in methods signatures
data lx-exception type ref to cx-sise-exception.
data l-message type string.
message e??@<ags-sise-error= into l-message.
lx-exception 7
cx-sise-exception7;create-from-sy< =.
+$%:E +E:(9$*1E E6)EP"%/2 lx-exception.
A. )ontinue process here AA

$ generic way to catch and handle
Exception at (% 1eel

"o handle )6-:%:E-E6)EP"%/2 you hae to catch it. %f you do that at (% 1ayer leel, you
should most of the time report the error to end user. "he class )l-sise-exception-reporter will
propose a set of method to make reporting easier. .or instance, to display the error message in
to the message area of we#dynpro , you can use method &report-error-to-message-area'.

%n order to manage &resuma#le' exception, you hae to use B*E./+E (2>%2, keywords in
the catch statements.

%f the exception you receie is &resuma#le' the flag &is-resuma#le' of the exception will #e set.
"hen it is up to you to decide if you want resume or not according to your functional need. "o
resume simply call &resume'. >hen resume is called, the process located 0ust after where the
exception has #een triggered will continue.
data lx-exception type ref to cx-sise-exception.
try.
cl-sise-#usiness-layer7;call-a-method< =.
catch *E./+E (2>%2, cx-sise-exception into lx-exception.
cl-sise-exception-reporter7;report-error-to-message-area< io-message-manager 7 wd-thisC;mo-message-manager
ix-agssise-exception 7 lx-exception =.
if lx-exceptionC;is-resuma#le 7 a#ap-true.
resume.
endif.
endtry.

You might also like