RAS プレイグラウンド English GitHub

RAS標準ライブラリ

エラーとイベントハンドラ

コンパイラに組み込まれている型です。

export function safeDivide(a: int, b: int): int {
    try {
        if (b == 0) throw new Error("0 では割れません");
        return a / b;
    } catch (e) {
        debug.print(e.code, e.description, e.rasFile, e.rasLine);
        return 0;
    }
}

export function watchInput() {
    const listener = Sheet1.on("Change", (target) => {
        debug.print(target.address);
    });
    listener.off();                       // 外す
}

VBA の On Error Resume Next は try { … } catch { resume; } と書きます。finally・using は仕様書 §5 を参照してください。

リファレンス

インターフェイス RAS_Error

catch (e) で受け取るエラー情報。

throw new Error("...") で作成し、throw e; で再送出できる。

#
code: int

エラー番号(VBA の Err.Number)。

#
description: string

エラーの説明(VBA の Err.Description)。

#
readonly message: string

description と同じ。

#
source: string

エラーの発生元(VBA の Err.Source)。

#
rasFile: string

エラーが発生した RAS ソースファイル。

#
rasLine: int

エラーが発生した RAS ソースの行番号(行番号付与が無効な場合は 0)。

core.d.ras

インターフェイス RAS_Listener

on / addEventListener で付けたイベントハンドラ。

off() で外す。フォームのコードビハインドで付けたものは、フォームが閉じると自動で外れる。

#
off(): void

イベントハンドラを外す。外したあとは呼ばれない(何度呼んでもよい)。

core.d.ras