Error object (JavaScript API for Office v1.0)

JavaScript API for Office v1.0

Provides specific information about an error that occurred during an asynchronous data operation.

Last modified: June 12, 2014

asyncResult.error

Properties

Name

Description

code

Gets the numeric code of the error.

name

Gets the name of the error.

message

Gets a detailed description of the error.

The Error object is accessed from the AsyncResult object that is returned in the function passed as the callback argument of an asynchronous data operation, such as the setSelectedDataAsync method of the Document object.

The following example uses the setSelectedDataAsync method to set the selected text to "Hello World!", and if that fails, displays the values of the name and message properties of the Error object.

function setText() {

    Office.context.document.setSelectedDataAsync("Hello World!", {},
        function (asyncResult) {
            if (asyncResult.status === "failed")
            var err = asyncResult.error; 
                write(err.name + ": " + err.message);
        });
}

// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

Supported clients

Excel 2013, Excel 2013 RT, Excel Online, Outlook 2013, Outlook 2013 RT, Outlook Web App, OWA for Devices, PowerPoint 2013, PowerPoint 2013 RT, Project 2013, Word 2013, Word 2013 RT

Library

Office.js

Namespace

Office

Show:
© 2014 Microsoft