Office.Error interface

提供有关异步数据操作期间发生的错误的具体信息。

注解

Error 对象是从作为异步数据操作的回调参数传递的函数中返回的 AsyncResult 对象访问的,例如 setSelectedDataAsync Document 对象的 方法。

属性

code

获取错误的数字代码。 有关错误代码的列表,请参阅 适用于 Office 的 JavaScript API 错误代码

message

获取错误的详细描述。

name

获取错误的名称。

属性详细信息

code

获取错误的数字代码。 有关错误代码的列表,请参阅 适用于 Office 的 JavaScript API 错误代码

code: number;

属性值

number

示例

// 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

获取错误的详细描述。

message: string;

属性值

string

示例

// 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

获取错误的名称。

name: string;

属性值

string

示例

// 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; 
}