Wriju's BLOG

.NET, Cloud and everything

WinJS Global Error Handling in JavaScript

In Windows Store Apps if any unhandled error comes it closes the application. This sliently happens to terminate the app. This is a default behavior. We can change this behavior by handling the “unhandled” errors.

app.onerror = function (e) {
    var message = e.detail.message;
    var description = e.detail.description;
    var code = e.detail.number;
    var stackTrace = e.detail.stack;

    var msgBox = new Windows.UI.Popups.MessageDialog(
        description, e.detail.errorMessage


    return true;

Now by saying return true

We are ensuring that application stays in the place and we continue to work. Else if we have return false then it will crash.

This behavior is not something to be tested in debug mode from Visual Studio. One should test it from the Apps list of Windows 8 desktop.

To test, put something like


As alert does not work in WinJS, it will crash the app.