title: PostgreSQL 9.5: Exception handling
body: <p>I have table called employee with two columns, and have created two functions for 
  insertion and updation operations. These two function will be called through another
  function which named as udf_3().</p>
  
  <p>I want to do exception handling on the third function that is <code>udf_3()</code> which should 
  give me the details of which function has error.</p>
  
  <p>--<strong>Table</strong>: <code>employee</code></p>
  
  <pre><code>create table employee
  (
   id int,
   name varchar(10)
  );
  </code></pre>
  
  <p>--<strong>Function</strong> 1: <code>udf_1()</code> used for insertion.</p>
  
  <pre><code>create or replace function udf_1()
  returns void as
  $body$
  begin
  
          insert into employee values(1,'Mak');
  end;
  $body$
  language plpgsql;
  </code></pre>
  
  <p>--<strong>Function</strong> 2: <code>udf_2()</code> used for updation.</p>
  
  <pre><code>create or replace function udf_2()
  returns void as
  $body$
  begin
  
          update employee
          set a_id = 99
          where name = 'Mak';
  
  end;
  $body$
  language plpgsql;
  </code></pre>
  
  <p>--<strong>Function</strong> 3: <code>udf_3()</code> used to call all above function.</p>
  
  <pre><code>create or replace function udf_3()
  returns int as
  $body$
  begin
      perform udf_1();
  
      perform udf_2();
  
      return 0;
  
      exception 
      when others then
          RAISE INFO 'Error Name:%',SQLERRM;
          RAISE INFO 'Error State:%', SQLSTATE;
          return -1;
  
  end;
  $body$
  language plpgsql;
  </code></pre>
  
  <p>--<strong>Function Calling</strong>:</p>
  
  <pre><code>select * from udf_3();
  </code></pre>
  
  <p><strong>Exception</strong>: </p>
  
  <pre><code>INFO:  Error Name:column "a_id" of relation "employee" does not exist
  INFO:  Error State:42703
  </code></pre>
  
  <p><strong>Problem</strong>: I am able to get the exception <strong>BUT</strong> not able to get from which function i got exception.</p>