Error Raised in Declaration Section - Not Handled
DECLARE
aname VARCHAR2 (5) := 'Big String';
BEGIN
DBMS_OUTPUT.put_line (aname);
EXCEPTION
WHEN VALUE_ERROR
THEN
DBMS_OUTPUT.put_line ('Handled!');
END;
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Trapped in Outer Block
BEGIN
DECLARE
aname VARCHAR2 (5) := 'Big String';
BEGIN
DBMS_OUTPUT.put_line (aname);
EXCEPTION
WHEN VALUE_ERROR
THEN
DBMS_OUTPUT.put_line ('Handled!');
END;
EXCEPTION
WHEN VALUE_ERROR
THEN
DBMS_OUTPUT.put_line ('Handled in outer block!');
END;
Handled in outer block!
What's a Developer to Do? Initialize Later!
BEGIN
DECLARE
aname VARCHAR2 (5);
PROCEDURE initialize
IS
BEGIN
aname := 'Big String'; -- pkg.func ();
END;
BEGIN
initialize;
DBMS_OUTPUT.put_line (aname);
EXCEPTION
WHEN VALUE_ERROR
THEN
DBMS_OUTPUT.put_line ('Handled!');
END;
EXCEPTION
WHEN VALUE_ERROR
THEN
DBMS_OUTPUT.put_line ('Handled in outer block!');
END;
Handled!