Office.Error interface
Provides specific information about an error that occurred during an asynchronous data operation.
Remarks
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.
Properties
code | Gets the numeric code of the error. For a list of error codes, see JavaScript API for Office error codes. |
message | Gets a detailed description of the error. |
name | Gets the name of the error. |
Property Details
code
Gets the numeric code of the error. For a list of error codes, see JavaScript API for Office error codes.
code: number;
Property Value
number
Examples
// To cause an error to be thrown, select a table or a matrix, and then call the setText function.
function setText() {
Office.context.document.setSelectedDataAsync("Hello World!",
function (asyncResult) {
if (asyncResult.status === "failed")
const error = asyncResult.error;
write(error.name + ": " + error.code + " - " + error.message);
});
}
// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message;
}
message
Gets a detailed description of the error.
message: string;
Property Value
string
Examples
// To cause an error to be thrown, select a table or a matrix, and then call the setText function.
function setText() {
Office.context.document.setSelectedDataAsync("Hello World!",
function (asyncResult) {
if (asyncResult.status === "failed")
const error = asyncResult.error;
write(error.name + ": " + error.message);
});
}
// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message;
}
name
Gets the name of the error.
name: string;
Property Value
string
Examples
// To cause an error to be thrown, select a table or a matrix, and then call the setText function.
function setText() {
Office.context.document.setSelectedDataAsync("Hello World!",
function (asyncResult) {
if (asyncResult.status === "failed")
const error = asyncResult.error;
write(error.name + ": " + error.message);
});
}
// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message;
}
Office Add-ins