Office.Error interface 
提供有关异步数据操作期间发生的错误的具体信息。
注解
从作为异步数据作的回调参数传递的函数中返回的 AsyncResult 对象(例如 Document 对象的 方法) setSelectedDataAsync 访问 Error 对象。
属性
| 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; 
}