In this post we will discuss throw keyword in detail.
What is throw?
In simple words throw is keyword used in error handling
Is throw keyword compulsory to use?
No, it is optional and in many cases it is not used.
What is the purpose of throw?
When we write a custom method then we have two choices.
First Choice:
Handle those errors and take appropriate action in our script. This is accomplished using catch keyword.
Second Choice:
Let somebody else handle those errors in that case we use throw which in simple language means that “An exception that has occurred I don’t know how to handle it so I am passing it to you” (you is Siebel here) and Siebel basically shows a pop-up displaying the description of the error that has occurred.
Let’s understand this with help of an example
try
{
//some logic to do something
}
catch(e)
{
if(e.toString() == “Say some particular error A”)
{
// do this
}
else
{
throw e;
}
}
finally
{
// make objects null
}
Now according to the above code if error has a some particular description then we handle it otherwise we just pass it on to Siebel which will display it to user.
When should we use throw?
throw is usually used in business service code which is going to be called from workflow. When an error occurs it will trigger the exception step of a workflow and assign the error information to Error Code and Error Description process properties of workflow. If I don’t use throw and just use blank catch
try
{
//some code
}
catch(e)
{
;
}
then the workflow will not get an exception and it will go on its merry way thinking everything is fine.
I hope this clears any doubts that you might have about using throw. In next part I will discuss how to suppress some particular error using catch.
<< Previous in series Next in series >>


(5 votes, average: 3.40 out of 5)