A SERVICE OF

logo

24 Chapter 3
Error Handling
Most MediaScript functions indicate an error condition by throwing an exception rather
than returning an error code. Exceptions can be trapped and handled using ECMAScript's
standard try/catch/finally mechanism.
For example, the Media object's load() method throws an exception if the file to be loaded
is not found. To trap this exception, you would write something like the following:
try
{
img.load(name @ "missingFile.tga");
}
catch (e)
{
// Here you can recover from the error. Possible
// actions include loading a default image,
// logging an error, or returning a 404.
}
If an exception is thrown while executing your script and no catch block traps it, the script
will terminate immediately. By default the error is logged to the ScriptErrors.log file
and returned to the client as an error response. You can disable logging by setting the
ScriptErrorLogging property to false in the global.properties configuration file.
For HTTP clients, you can disable the returning of the error response as HTML by setting
the ReturnHtmlErrors property to false in global.properties. If error HTML is disabled
MediaRich will respond with a 500 Internal Server Error status code.
File Object
The File object provides access to an external file.
Object Methods
new File() constructor
clear()
close()
copy()
exists()
getFileName()
getFilePath()
getLastModified()
getLastAccessed()
getParentPath()
getSize()
isDirectory()
isFile()