locked
Metro JavaScript try/catch fails RRS feed

  • Question

  • Anyone else having problems with try/catch in a Metro JavaScript app failing - i.e. catching no exceptions?  The first symptom is that the app blows up if you include standard jQuery, as jQuery depends on a functioning try/catch.  Also fails to catch an exception when calling a non-existent function on a winRT API object.  I'm surprised I haven't seen any complaints, as this is a complete show-stopper for any serious work.

    Visual Studio standard JavaScript windows Metro Style Fixed Layout project.

    Microsoft Visual Studio 11
    Version 11.0.40825.2 PREREL
    Microsoft .NET Framework
    Version 4.5.65530 PREREL
    Installed Version: Ultimate
    Microsoft Visual C# 11 Developer Preview   01019-315-4422943-70030

    Monday, February 27, 2012 10:37 PM

All replies

  • Hi GlennW23,

    Can you provide more details on the exceptions which aren't being caught? If I generate an exception in a try/catch block in a dummy function it gets caught as expected.

    function button_click(e)
    {
        try 
        {
            Debug.writeln("button_click");
            thisFunctionDoesNotExist();
         } 
        catch(ex)
        {
            Debug.writeln("caught exception: " + ex);
        }
    }
    Many people are using jQuery successfully in Metro style apps so there is likely something unusual about your specific scenario.

    --Rob

    Tuesday, February 28, 2012 2:12 AM
    Moderator
  • Aha, I didn't understand what this line did:

    // Uncomment the following line to enable first chance exceptions.
    //Debug.enableFirstChanceException(true);

    jQuery has a browser portability test in a try/catch that was firing and throwing into the debugger first with this uncommented.


    Friday, March 2, 2012 10:41 PM
  • Note that first chance exceptions are now enabled through Visual Studio, as described here: http://msdn.microsoft.com/en-us/library/windows/apps/6d156cff-36c6-425a-acf8-e1f02d4f7869#FirstChance.

    Monday, March 5, 2012 11:07 PM