OfficeExtension.Error class

要求の処理中にエラーが原因で promise が拒否された場合に、 によって context.sync()返されるエラー オブジェクト。

プロパティ

code

"InvalidArgument" などのエラー コード文字列。

debugInfo

デバッグ情報 (エラーの詳細なログ記録に役立ちます。つまり、 を使用して JSON.stringify(...))。

innerError

内部エラー (該当する場合)。

message

Office アプリケーションから渡されたエラー メッセージ。

name

エラー名: "OfficeExtension.Error"

stack

スタック トレース (該当する場合)。

traceMessages

を呼び出すcontext.sync()前に、呼び出しによって追加されたメッセージ (存在するcontext.trace()場合) をトレースします。 エラーが発生した場合、エラーが発生する前に実行されたすべてのトレース メッセージが含まれます。 これらのメッセージは、プログラムの実行シーケンスを監視し、エラーのケースを検出するのに役立ちます。

プロパティの詳細

code

"InvalidArgument" などのエラー コード文字列。

code: string;

プロパティ値

string

debugInfo

デバッグ情報 (エラーの詳細なログ記録に役立ちます。つまり、 を使用して JSON.stringify(...))。

debugInfo: DebugInfo;

プロパティ値

innerError

内部エラー (該当する場合)。

innerError: Error;

プロパティ値

message

Office アプリケーションから渡されたエラー メッセージ。

message: string;

プロパティ値

string

name

エラー名: "OfficeExtension.Error"

name: string;

プロパティ値

string

stack

スタック トレース (該当する場合)。

stack: string;

プロパティ値

string

traceMessages

を呼び出すcontext.sync()前に、呼び出しによって追加されたメッセージ (存在するcontext.trace()場合) をトレースします。 エラーが発生した場合、エラーが発生する前に実行されたすべてのトレース メッセージが含まれます。 これらのメッセージは、プログラムの実行シーケンスを監視し、エラーのケースを検出するのに役立ちます。

traceMessages: string[];

プロパティ値

string[]

// The following example shows how you can instrument a batch of commands
// to determine where an error occurred. The first batch successfully
// inserts the first two paragraphs into the document and cause no errors.
// The second batch successfully inserts the third and fourth paragraphs
// but fails in the call to insert the fifth paragraph. All other commands
// after the failed command in the batch are not executed, including the
// command that adds the fifth trace message. In this case, the error
// occurred after the fourth paragraph was inserted, and before adding the
// fifth trace message.

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the document body.
    const body = context.document.body;

    // Queue a command to insert the paragraph at the end of the document body.
    // Start a batch of commands.
    body.insertParagraph('1st paragraph', Word.InsertLocation.end);
    // Queue a command for instrumenting this part of the batch.
    context.trace('1st paragraph successful');

    body.insertParagraph('2nd paragraph', Word.InsertLocation.end);
    context.trace('2nd paragraph successful');

    // Synchronize the document state by executing the queued-up commands,
    // and return a promise to indicate task completion.
    await context.sync();

    // Queue a command to insert the paragraph at the end of the document body.
    // Start a new batch of commands.
    body.insertParagraph('3rd paragraph', Word.InsertLocation.end);
    context.trace('3rd paragraph successful');

    body.insertParagraph('4th paragraph', Word.InsertLocation.end);
    context.trace('4th paragraph successful');

    // This command will cause an error. The trace messages in the queue up to
    // this point will be available via Error.traceMessages.
    body.insertParagraph(0, '5th paragraph', Word.InsertLocation.end);
    // Queue a command for instrumenting this part of the batch.
    // This trace message will not be set on Error.traceMessages.
    context.trace('5th paragraph successful');
    await context.sync();
}).catch(function (error) {
    if (error instanceof OfficeExtension.Error) {
        console.log('Trace messages: ' + error.traceMessages);
    }
});

// Output: "Trace messages: 3rd paragraph successful,4th paragraph successful"