what is try catch

Naveen31
Giga Contributor

Can You please explain What is TRY CATCH

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Naveen,

basically try catch block is used to handle exceptions and is good practice

Example: consider an example where you need to run a background script which would update 1000 records on table based on some condition; such as update field and do concatenation etc

if you don't use try catch block and if the update fails because of some reason because of invalid character etc the subsequent records won't be updated and code would break.

if you use try catch block then it would log the exception and proceed to the next records; in this way only that record won't get updated and all others for which exception is not thrown would get updated

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi Naveen,

check the explaination provided to the below thread, it will be very useful for understanding the try/catch concept:

https://community.servicenow.com/community?id=community_question&sys_id=53371ed8dbfe6700107d5583ca96...

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Naveen,

basically try catch block is used to handle exceptions and is good practice

Example: consider an example where you need to run a background script which would update 1000 records on table based on some condition; such as update field and do concatenation etc

if you don't use try catch block and if the update fails because of some reason because of invalid character etc the subsequent records won't be updated and code would break.

if you use try catch block then it would log the exception and proceed to the next records; in this way only that record won't get updated and all others for which exception is not thrown would get updated

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader