Just a quick example:
fun main(): String? {
val response: String? = null
meterRegistry.timer("name").record {
response = getResponse() // throws exception
}
return response
}
In that case getResponse() throws an exception and there is no catch in the main method. Does it still record to grafana?
CodePudding user response:
Looking at the source code…
@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);
}
}
…you can see that the timing is recorded also in case of exceptions (because of the finally
block).