只是一個簡單的例子:
fun main(): String? {
val response: String? = null
meterRegistry.timer("name").record {
response = getResponse() // throws exception
}
return response
}
在這種情況下, getResponse() 會拋出例外并且 main 方法中沒有捕獲。它仍然記錄到grafana嗎?
uj5u.com熱心網友回復:
看原始碼……
@Override
public void record(Runnable f) {
final long s = clock.monotonicTime();
try {
f.run();
} finally {
final long e = clock.monotonicTime();
record(e - s, TimeUnit.NANOSECONDS);
}
}
……您可以看到,在出現例外(因為finally塊)的情況下也記錄了時間。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/339703.html
上一篇:如何在片段串列中找到特定片段?
