Monday, October 29, 2012

EXCEPTION HANDLING using TRY and CATCH

CustTable custTable;
;
try
{
custTable.AccountNum ="0002";
custTable.custGroup ="20";
custTable.Name ="Demonstration of try catch";
if (!custTable.validateWrite())
{
throw error("Record failed validation");
}
custTable.insert();
info("Record was inserted in database");
}
catch (Exception::error)
{
error("There was an error while inserting the
record.");
}

_________________________________________________________________________________

CustTable custTable;
;
try
{
custTable.AccountNum =“0001”;

custTable.custGroup =“50”;
custTable.Name =“Example of try catch”;
custTable.insert();
}
catch (Exception::error)
{
error(“There was an error while inserting the
record.”);
}
catch (Exception::deadlock)
{
retry;
}


_________________________________________________________________________________
//Throw Statement


try
{
select custTable
where custTable.accountNum == '1019';
if (!custTable.RecId)
throw error("Customer does not exist");

}
catch (exception::error)
{
error ("Process was aborted");
}

No comments: