+ Start a Discussion
Big EarsBig Ears 

Error handling when a trigger calls a number of classes

Dear all,

 

Just a quick question.

 

I have a trigger that calls a series of methods within Apex classes when a contract is activated. Currently, if one of those methods causes an exception, the trigger assumes it is unhandled, even if there is error handling within the apex class. Is there a way of passing the error handling back "up" to the trigger, so that the UI doesn't show an ugly exception page?

 

With thanks,

Andy 

lvivaninlvivanin
This sample code is working for me - Though the UI message does not look that good but I getting the exception message defined in my class method.

public class testExpt
{
public class GeneralException extends Exception

{

}
public void exptTesting(Master_Object__c[] testObjectArray)
{
for (Master_Object__c t: testObjectArray)
{
if(t.TestNumber__c < 25.00)
{
throw new GeneralException('This is bad number');
}
}
}
}

 

trigger TestOnMasterObject on Master_Object__c (before insert) {

testExpt testCls = new testExpt();

testCls.exptTesting(system.trigger.new);


}