Today we are going to discuss basic error handling technique while using eScript. As a script is written by a developer according to his perception of the requirement given to him so many times it is far from perfect and there are chances of breaking it in middle of processing, thus resulting in failure of the complete functionality.
So, it is very important to handle the errors and do the cleanup so that script can exit gracefully rather than giving a weird error message to the user causing him to panic. The basic technique that is used to handle error is use the below given constructs in the script that you are writing.
- try
- catch
- finally
- throw
Explanation of keywords:
Try : It is the construct that is used encapsulate the code that can fail.
Catch: As the name suggests it catches any exception or error that happens in code included in Try block
Finally: This is the code this executed before processing of the script stops.
throw: It is construct that is used to make sure that the execution of the script stops and control is returned back to the object from where the script was invoked. It works same way as TheApplication().RaiseErrorText() but we cannot customize the error message that is displayed to the user.
Basic Usage:
The basic use of the these constructs is
try
{
//normal code here
}//end of try block
catch(e) //start of catch block just after try
{
// your error handling code goes here
// which is usually display User friendly error message rather than weird technical message
throw e; //this is optional it stops the execution of the script
// but the finally block is still executed
}
finally //start of finally block
{
//this will be executed weather an exception occurs or not
// so the normal practice is just to nullify the objects here
}


5 Comments at "try-catch-finally and throw - Part 1"
Good
Good work.Thanks and keep it up.
Hey,
Could someone please throw some more light on “catch” and “throw” because even though throw isnt there still the user gets an error message when the error is encountered…so what is the benefit of having throw??
Thanks in advance
Hi Divya,
Hopefully this post will clear your doubts about throw
http://siebelunleashed.com/siebel-try-catch-finally-and-throw-part-4/
Hey Neel,
Thanks for the post … Must say the way u explain is so superb that even a huge mountain seems a pebble…great work buddy…
Comment Now!