Oracle: Capturing Specific Oracle Message with EXCEPTION_INIT
<p>I want to handle an exception for <code>ORA-000942</code> and am following this <a href="http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/errors.htm#i9355" rel="nofollow noreferrer">manual</a> and this <a href="https://stackoverflow.com/questions/6020450/oracle-pl-sql-raise-user-defined-exception-with-custom-sqlerrm">discussion</a>. Since this is an <code>ORA-</code> error with no predefined name, I want to use <code>exception_init.</code> </p>

<p>When I run this code, I continue to get the <code>ORA-000942</code> message, but not as expected via the procedure level handler.</p>

<pre><code>create table foobar (foobar_id varchar(1));

declare

 procedure p_add_to_foobar
 is
 p_missing_table exception;
 pragma exception_init(p_missing_table, -00942);

 begin
 insert into foobaz   
 select '1' from dual;

  exception
  when p_missing_table then
  dbms_output.put_line('MISSING TABLE'); 
  end p_add_to_foobar;  


 begin
 p_add_to_foobar;
 dbms_output.put_line('DONE');
 end;
</code></pre>

<p><strong>Question:</strong></p>

<ol>
<li>How do I get my procedure level exception to handle the <strong>-942</strong> error?</li>
</ol>