Exception Handling

An HD DVD player may throw exceptions during the execution of script, and if not caught will result in a player crash (showing an error code of 0x4094C00C on Toshiba or 0xC667000B on Xbox).  While it's always a good idea to check conditions which could cause an exception to be thrown, an exception could still be thrown, so write your code in such a way to catch those exceptions and recover gracefully. 

Your title should use try-catch exception handling in all entry points including all global code, event handlers, and function callbacks.

Detailed information about the conditions under which an exception may be thrown is detailed for each API defined in Annex Z of the DVD Specifications for High Definition Video.  So, before making a call to an API, check conditions under which an exception may be thrown.  For example, calling XMLParser.parse will throw an exception if XMLParser.status is not equal to XMLParser.READY, so you should check status before proceeding.

While specific exceptions can be thrown based on conditions, do not write script that relies on specific exceptions.  Both exceptions and callback status values are meant to be informative.  This means that they need only to signify success or failure and not specific information about what precisely caused the failure.

Keep try blocks to small chunks of code and attempt recovery wherever possible. 

    try

    {

        if (XMLParser.status() == XMLParser.READY)

        {

            XMLParser.parse("file:///dvddisc/ADV_OBJ/data.xml",

parseCallback);

        }

        else

        {

            //parseFailed would be a function that proceeds appropriately

            //when success path can not be followed

            parseFailed();

        }

    }

    catch (ex)

    {

        //utility from "Helpful Tracing Routines" that writes diagnostic info

        TraceError("EXCEPTION", ex, arguments.callee);

        //parseFailed would be a function that proceeds appropriately

        //when success path can not be followed

        parseFailed();

  }

Because using try-catch may make debugging difficult, you should use conditional compilation around calls to try-catch blocks.  Conditional compilation is a proprietary Microsoft extension for Jscript that can be used during development with the Microsoft HDi simulator from the Interactivity Jumpstart Kit, the Xbox HD DVD emulator, and some software players.  For more information on using conditional compilation during HDi development, read: https://blogs.msdn.com/ptorr/archive/2007/06/01/using-conditional-compilation-in-hdi.aspx

As demonstrated above, all catch blocks should also contain diagnostic trace information to further assist during development.  For more information on helpful tracing routines, read: https://blogs.msdn.com/ptorr/archive/2007/06/27/helpful-tracing-routines.aspx