Sie sind auf Seite 1von 1

7no(led#e 5pert for PL1S2L 6%-%- - E'ceptions - Client-Server Error Communication

1> )andle the server-side e'ception% >1 0)EN Oracle provides the no_"a"ies_allo(ed RAISE_APPLICATION_ERROR procedure to communicate application-specific errors from the server T)EN side usuall! a data"ase tri##er$ to the client-side application% This "uilt-in procedure is the onl! mechanism availa"le for 1> a server-side& pro#rammer-defined e'ception to the client side in such a (a! that the client process can communicatin# @@ S2LERR= (ill return the messa#e passed into the handle the e'ception% @@ RAISE_APPLICATION_ERROR "uilt-in% >1 )ere is an e'ample of a call to this "uilt-in* <:=S_OATPAT%PAT_LINE S2LERR=$/ RAISE_APPLICATION_ERROR -+,,,-& .Invalid Re#istration.$/ EN</ 0hen !ou call RAISE_APPLICATION_ERROR& it is as thou#h an e'ception has "een raised (ith the RAISE statement% E'ecution of the current PL1S2L "loc3 halts immediatel!& and all the effects of the pro#ram are rolled "ac3% The "uilt-in returns a pro#rammer-defined error num"er and messa#e "ac3 to the client component of the application% 4ou can then use and e'ception the E5CEPTION_INIT pra#mahandlers to handle the error in a #raceful& user-friendl! manner% The error num"er !ou specif! must "e "et(een +,,,, and +,666 so !ou do not conflict (ith an! Oracle error num"ers% The error messa#e can "e up to +7 "!tes in len#th/ if it is lon#er& it (ill not a"ort the call to RAISE_APPLICATION_ERROR/ the procedure (ill simpl! truncate an!thin# "e!ond the +7% The e'ception handler architecture& com"ined (ith RAISE_APPLICATION_ERROR and the On-Error tri##er& allo(s !our front end application to rel! on "usiness rules em"edded in the data"ase to perform validation and communicate pro"lems to the user% 0hen !ou ma3e use of RAISE_APPLICATION_ERROR& ho(ever& it is entirel! up to !ou to mana#e the error num"ers and messa#es% To help mana#e !our error codes and provide a consistent interface (ith (hich developers can handle server errors& !ou mi#ht consider "uildin# a pac3a#e% RAISE_APPLICATION_ERROR in a Database Trigger Suppose !ou need to implement a data"ase tri##er (hich stops records from "ein# inserted into the data"ase if the person is less than -8 !ears old% The code for this tri##er (ould loo3 li3e this* CREATE OR REPLACE TRI99ER minimum_a#e_chec3 :E;ORE INSERT ON emplo!ee ;OR EAC) RO0 :E9IN I; A<<_=ONT)S *ne(%"irth_date& -8>-+$ ? S4S<ATE T)EN RAISE_APPLICATION_ERROR -+,,,-& .Emplo!ees must at least ei#hteen !ears of a#e%.$/ EN< I;/ EN</ On the client side& a pro#ram can "e (ritten li3e the follo(in# to detect and handle this e'ception* <ECLARE 1> <eclare the e'ception% >1 no_"a"ies_allo(ed E5CEPTION/ 1> Associate the name (ith the error num"er used in the tri##er% >1 PRA9=A E5CEPTION_INIT no_"a"ies_allo(ed& -+,,,-$/ :E9IN 1> Attempt to insert the emplo!ee% >1 INSERT INTO emplo!ee %%% / E5CEPTION

E'ceptions - Client-Server Error Communication

Pa#e + -

Das könnte Ihnen auch gefallen