Error Checking with Functions

If a function fails, then some functions return a special value. Consider the following example:

  • To allow a script to read from or write to a file, the Clib.fopen method opens or creates this file.

  • If the script calls the Clib.fopen method but this method cannot open a file, then the method returns null.

  • If the script then attempts to read from or write to this file, then Siebel CRM creates an error.

To prevent this error, you can use the following code to determine if Clib.fopen returns null when it attempts to open a file. If it does return null, then you can write code that aborts the script and displays an error message:

var fp = Clib.fopen("myfile.txt", "r");
var fp = Clib.fopen("myfile.txt", "r");
if (null == fp)//make sure null is not returned
{
   TheApplication().RaiseErrorText("Error with fopen as returned null " + 
   "in the following object: " + this.Name() + " " + e.toString() + e.errText());
}

For more information, see Overview of the Clib Object.