Explanation of ‘e’ in catch block?
‘e’ in catch block is an object that contains information about the error or exception that has happened. So, in case if you would like to show the actual error that has happened that you could use the following code
catch(e)
{
TheApplication().RaiseErrorText(“User Friendly Message” + e.toString());
}
It is not necessary to write an ‘e’ here you can use any work that is not a reserved word. For example
catch(exp_obj)
{
TheApplication().RaiseErrorText(“User Friendly Message” + exp_obj.toString());
}
Caution while using Finally.
Verify that the objects that you are trying to nullify inside finally are not define inside an if block as it could result in Object not defined error if flow never goes inside If block. For example
try
{
if(this.GetFieldValue(“Status”) == “Urgent”)
{
var BO = TheApplication().GetBusObject(“Contact”);
var BC = BO.GetBusComp(“Contact”);
// rest of the logic
}
}
catch(expobj)
{
//you catching logic or you can use throw here
}
finally
{
BO = BC = null;
}
In this code if value of the field Status is not urgent then variables BO and BC will never be declared which can result in variables not defined error. So either they should be declared outside if block or they should be nullified in the if block.
<< Previous in series Next in series >>
(3 votes, average: 4 out of 5)
O comments at "try catch finally and throw - Part 2"
Comment Now!