--
-- ### Procedure application exception check
-- 
--

drop if exists table t1;
create table t1 ( a string(30));

drop if exists procedure throwit;

@
create procedure throwit(a in string(30), msg out string(30)) return int
begin
   var c int;
   insert into t1 ( a ) values ( :a );
   :c = 3;
   -- ( select count(*) from t1 );
   if :c > 10
   then
	throw 'Too many inserts';
   end;
   :msg = 'OK';
   return 0;
exception when core_op
then
    -- exception for invalid objects is catched here
    :msg = :excep_info;
    return 1;
exception when other
then
    -- exception is catched, exception information is assigned from special var excep_info to return parameter 
    :msg = :excep_info;
    return 2;
end;
@

-- table does not exist
:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;

drop table t1;

:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;

create table t1 ( ax string(30));

:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;

drop table t1;
create table t1 ( a string(30));

desc table t1;

:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;
:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;
:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;
:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;
:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;
:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;
:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;
:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;
:r = call throwit('XXX', :msg);
print 'Return Value = ' | :r | ' # Message = ' | :msg;

