tryRunning
var result = _exceptions.tryCatch {
    tryRunning {
        _console.log("tryRunning执行了1")
        _exceptions.throwException { setMessage("xxx") }
        _console.log("不会执行到这里")
        "没有异常"
    }
    catchException {
        _console.log("catchException执行了")
        "出现异常" + it.getMessage()
    }
    finallyRun { _console.log("finally run 1...") }
}
_console.log("result", result)
result = _exceptions.tryCatch {
    tryRunning {
        _console.log("tryRunning执行了2")
        "没有异常"
    }
    catchException {
        _console.log("不会执行到这里")
        "出现异常" + it.getMessage()
    }
    finallyRun { _console.log("finally run 2...") }
}
_console.log("result", result)
def result = $exceptions.tryCatch {
    tryRunning {
        $console.log("tryRunning执行了1")
        $exceptions.throwException { setMessage("xxx") }
        $console.log("不会执行到这里")
        "没有异常"
    }
    catchException {
        $console.log("catchException执行了")
        "出现异常" + it.getMessage()
    }
    finallyRun { $console.log("finally run 1...") }
}
$console.log("result", result)
result = $exceptions.tryCatch {
    tryRunning {
        $console.log("tryRunning执行了2")
        "没有异常"
    }
    catchException {
        $console.log("不会执行到这里")
        "出现异常" + it.getMessage()
    }
    finallyRun { $console.log("finally run 2...") }
}
$console.log("result", result)
let result = $exceptions.tryCatch((exceptionCatcher) => {
    exceptionCatcher.tryRunning(() => {
        $console.log("tryRunning执行了1")
        $exceptions.throwException((eb) => {
            eb.setMessage("xxx")
        })
        $console.log("不会执行到这里")
        return "没有异常"
    })
    exceptionCatcher.catchException((it) => {
        $console.log("catchException执行了")
        return "出现异常" + it.getMessage()
    })
    exceptionCatcher.finallyRun(() => {
        $console.log("finally run 1...")
    })
})
$console.log("result", result)
result = $exceptions.tryCatch((exceptionCatcher) => {
    exceptionCatcher.tryRunning(() => {
        $console.log("tryRunning执行了2")
        return "没有异常"
    })
    exceptionCatcher.catchException((it) => {
        $console.log("不会执行到这里")
        return "出现异常" + it.getMessage()
    })
    exceptionCatcher.finallyRun(() => {
        $console.log("finally run 2...")
    })
})
$console.log("result", result)
local result = _exceptions:tryCatch(function(exceptionCatcher)
    exceptionCatcher:tryRunning(function()
        _console:log("tryRunning执行了1")
        _exceptions:throwException(function(eb)
            eb:setMessage("xxx")
        end)
        _console:log("不会执行到这里")
        return "没有异常"
    end)
    exceptionCatcher:catchException(function(it)
        _console:log("catchException执行了")
        return "出现异常" .. it:getMessage()
    end)
    exceptionCatcher:finallyRun(function()
        _console:log("finally run 1...")
    end)
end)
_console:log("result", result)
result = _exceptions:tryCatch(function(exceptionCatcher)
    exceptionCatcher:tryRunning(function()
        _console:log("tryRunning执行了2")
        return "没有异常"
    end)
    exceptionCatcher:catchException(function(it)
        _console:log("不会执行到这里")
        return "出现异常" .. it:getMessage()
    end)
    exceptionCatcher:finallyRun(function()
        _console:log("finally run 2...")
    end)
end)
_console:log("result", result)
<?php
$result = $exceptions->tryCatch(function ($exceptionCatcher) use ($console, $exceptions) {
    $exceptionCatcher->tryRunning(function () use ($console, $exceptions) {
        $console->log("tryRunning执行了1");
        $exceptions->throwException(function ($eb) {
            $eb->setMessage("xxx");
        });
        $console->log("不会执行到这里");
        return "没有异常";
    });
    $exceptionCatcher->catchException(function ($it) use ($console) {
        $console->log("catchException执行了");
        return "出现异常" . $it->getMessage();
    });
    $exceptionCatcher->finallyRun(function () use ($console) {
        $console->log("finally run 1...");
    });
});
$console->log("result", $result);
$result = $exceptions->tryCatch(function ($exceptionCatcher) use ($console) {
    $exceptionCatcher->tryRunning(function () use ($console) {
        $console->log("tryRunning执行了2");
        return "没有异常";
    });
    $exceptionCatcher->catchException(function ($it) use ($console) {
        $console->log("不会执行到这里");
        return "出现异常" . $it->getMessage();
    });
    $exceptionCatcher->finallyRun(function () use ($console) {
        $console->log("finally run 2...");
    });
});
$console->log("result", $result);
def fn1(exceptionCatcher):
    def fn2():
        _console.log("tryRunning执行了1")
        _exceptions.throwException(lambda eb: eb.setMessage("xxx"))
        _console.log("不会执行到这里")
        return "没有异常"
    exceptionCatcher.tryRunning(fn2)
    def fn3(it):
        _console.log("catchException执行了")
        return "出现异常" + it.getMessage()
    exceptionCatcher.catchException(fn3)
    def fn4():
        _console.log("finally run 1...")
    exceptionCatcher.finallyRun(fn4)
result = _exceptions.tryCatch(fn1)
_console.log("result", result)
def fn5(exceptionCatcher):
    def fn6():
        _console.log("tryRunning执行了2")
        return "没有异常"
    exceptionCatcher.tryRunning(fn6)
    def fn7(it):
        _console.log("不会执行到这里")
        return "出现异常" + it.getMessage()
    exceptionCatcher.catchException(fn7)
    def fn8():
        _console.log("finally run 2...")
    exceptionCatcher.finallyRun(fn8)
result = _exceptions.tryCatch(fn5)
_console.log("result", result)
# encoding: utf-8
result = $exceptions.tryCatch { |exceptionCatcher|
  exceptionCatcher.tryRunning {
    $console.log("tryRunning执行了1")
    $exceptions.throwException { |eb| eb.setMessage("xxx") }
    $console.log("不会执行到这里")
    "没有异常"
  }
  exceptionCatcher.catchException { |it|
    $console.log("catchException执行了")
    "出现异常" + it.getMessage()
  }
  exceptionCatcher.finallyRun { $console.log("finally run 1...") }
}
$console.log("result", result)
result = $exceptions.tryCatch { |exceptionCatcher|
  exceptionCatcher.tryRunning {
    $console.log("tryRunning执行了2")
    "没有异常"
  }
  exceptionCatcher.catchException { |it|
    $console.log("不会执行到这里")
    "出现异常" + it.getMessage()
  }
  exceptionCatcher.finallyRun { $console.log("finally run 2...") }
}
$console.log("result", result)
Last modified: 30 October 2025