locked
global exception handling RRS feed

  • Question

  • Is there somewhere in the WinJS/Windows framework where all exceptions bubble up to?  

    I am looking for somewhere to put my code for global exception handling - you know, to catch exceptions I have not handled elsewhere.

    I have reviewed the following articles/tutorials and I get all that, but they do not answer this question.

    http://msdn.microsoft.com/en-us/library/windows/apps/hh700337.aspx

    and  http://msdn.microsoft.com/en-us/library/windows/apps/hh974350.aspx 

    Thanks


    Phil

    Monday, February 24, 2014 2:53 PM

Answers

All replies

  • You have two options for a global handler: window.onerror or WinJS.Application.onerror. The latter is best as it wraps the former and also picks up unhandled exceptions that arise from inside WinJS.Application event handlers, which aren't caught by window.onerror. But there's no harm in using both.

    See my blog post http://kraigbrockschmidt.com/blog/?p=1150 for some additional details on this.

    Kraig

    Author, Programming Windows Store Apps with HTML, CSS, and JavaScript, Second Edition, a free ebook from Microsoft Press. First edition (for Windows 8) also available.


    • Marked as answer by pdschuller_ Wednesday, February 26, 2014 4:21 PM
    Monday, February 24, 2014 5:01 PM
  • Also a good article here.

    Phil

    Wednesday, February 26, 2014 4:22 PM
  • Thanks for your answer.

    Can you tell me how I can get the stack trace out of the error object?

    btw, in your blog you use err.detail  

    That returns [object, Object] for me.  I had to use err.detail.errorMessage

    Thanks



    Phil

    Wednesday, February 26, 2014 4:30 PM
  • Thanks for the correction. As for the stack trace info, I don't believe the app has access to it directly from the error object--not something I've explored so I don't know how you'd get to it, if it's even possible.
    Wednesday, February 26, 2014 4:32 PM