x

Catching Exceptions

How would I go about catching this error before it got to the when others clause? I KNOW I NEED TO WRAP THE INNER BLOCK WITH A BEGIN AND END BUT I THINK I AM PUTTIN ONE OF THE BEGIN IN THE WRONG PLACE

Using oracle

CREATE OR REPLACE PROCEDURE example1 

(
  p_first_name IN varchar2)

as
    v_test_variable varchar(4) := p_first_name;
BEGIN
 BEGIN
  DBMS_OUTPUT.PUT_LINE('Exception Propagation Example 1');
 EXCEPTION
 when others then
  DBMS_OUTPUT.PUT_LINE('An error occured in the declaration section ');
END ;


EXCEPTION
    WHEN value_error THEN
    DBMS_OUTPUT.PUT_LINE('You cant put ['||V_TEST_VARIABLE || '] in a 4 character string.');
END example1;
/
show errors
    EXEC EXAMPLE1('hello')
more ▼

asked Oct 10 '11 at 07:06 PM in Default

sqlnewb gravatar image

sqlnewb
216 26 30 31

(comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x401
x375
x6

asked: Oct 10 '11 at 07:06 PM

Seen: 547 times

Last Updated: Oct 10 '11 at 11:47 PM