background image
<< Handling Custom Exceptions | Using Triggers >>
<< Handling Custom Exceptions | Using Triggers >>

Using EXCEPTION Statements

Handling Errors and Exceptions
Developing and Using Stored Procedures 4-45
BEGIN -- check that score is valid
IF n_score > max_score OR n_score < 0 THEN
RAISE score_wrong;
END IF;
END;
-- calculate the score
running_total := n_score * n_weight;
RETURN running_total;
EXCEPTION
WHEN weight_wrong THEN
DBMS_OUTPUT.PUT_LINE(
'The weight of a score must be between 0 and ' || max_weight);
RETURN -1;
WHEN score_wrong THEN
DBMS_OUTPUT.PUT_LINE(
'The score must be between 0 and ' || max_score);
RETURN -1;
END calculate_score;
Compile and save
emp_eval
Body
See Also:
Oracle Database PL/SQL Language Reference for information on the
syntax of exception declarations