You need to sign in to do that
Don't have an account?
hramani
Capturing an exception in a catch block from another method salesforce
I have method , method1() with a try catch block. I also have 2 more methods, method2() and method3() which does some operation and throws an exception.
I want to catch that exception and perform my operation based on the exception message. Below is the code.
I’m getting error here. Please help.
public void static method1(){
try{
Calls method
}catch(Exception ex){
if (ex == ‘Configuration JSON value limit exceeded’){
//DO AN OPERATION AND THROW A CUSTOM EXCEPTION
}
else if(‘RuleAction HTMLContent limit exceeded’){
//DO A DIFFERENT OPERATION AND THROW A CUSTOM EXCEPTION
}
}
}
public void static method2(){
If (//CONDITION SATISFIES){
Calls method3();
}
Else{
throw new StringException('Configuration JSON value limit exceeded');
}
}
public void static method3(){
If (//CONDITION SATISFIES){
Perform an operation
}
else
{
throw new StringException('RuleAction HTMLContent limit exceeded');
}
}
I want to catch that exception and perform my operation based on the exception message. Below is the code.
I’m getting error here. Please help.
public void static method1(){
try{
Calls method
}catch(Exception ex){
if (ex == ‘Configuration JSON value limit exceeded’){
//DO AN OPERATION AND THROW A CUSTOM EXCEPTION
}
else if(‘RuleAction HTMLContent limit exceeded’){
//DO A DIFFERENT OPERATION AND THROW A CUSTOM EXCEPTION
}
}
}
public void static method2(){
If (//CONDITION SATISFIES){
Calls method3();
}
Else{
throw new StringException('Configuration JSON value limit exceeded');
}
}
public void static method3(){
If (//CONDITION SATISFIES){
Perform an operation
}
else
{
throw new StringException('RuleAction HTMLContent limit exceeded');
}
}
PFB the sameple code. It will be working fine.
you can test above code in anonymous window as like below
Also, Here some useful links.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_custom.htm
Hope it helps. If it helps, mark it as best answer and mark it as solved. it heps out community clean,
Regards,
Navin
All Answers
PFB the sameple code. It will be working fine.
you can test above code in anonymous window as like below
Also, Here some useful links.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_custom.htm
Hope it helps. If it helps, mark it as best answer and mark it as solved. it heps out community clean,
Regards,
Navin