You need to sign in to do that
Don't have an account?
Vishnu Santhosh
Will the Outer methods with Try-Catch block catches exception of Inner methods ?
Hi,
I am new to Apex Development and am on the way of learning and discovering it more.
Consider this scenario :
Class { Method 1 { try{ //Statement 1 //Statement 2 ...... method2(params) ............... } catch(Exception ex) { //throws exception here } } Method 2 { //Some statements }
Will the Try- catch block in Method 1 catches exception if there is any exception/error thrown in the method 2 ?
New to this. Correct me if i am wrong :)
Thank you
You might need to make a call to the method 2 from method 1 so that Try- catch block in Method 1 catches exception if there is any exception/error thrown in the method 2 .
It will finally depend on your business requirement and you will need to be sure you are following best practices to avoid any other issues coming up while customizing such thing.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_trycatch_example.htm
https://www.levelupsalesforce.com/apex-try-catch
Hope above information helps. Please mark as Best Answer so that it can help others in future.
Thanks.
All Answers
You might need to make a call to the method 2 from method 1 so that Try- catch block in Method 1 catches exception if there is any exception/error thrown in the method 2 .
It will finally depend on your business requirement and you will need to be sure you are following best practices to avoid any other issues coming up while customizing such thing.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_trycatch_example.htm
https://www.levelupsalesforce.com/apex-try-catch
Hope above information helps. Please mark as Best Answer so that it can help others in future.
Thanks.
Method 1 is calling the Method 2 as " method2(params)". Sorry for not mentioning that.
So, Method 1 will catch any errors thrown at Method 2 i believe. Got it.
Thank you so much for answering :)