Marc Knaup
10/16/2020, 9:52 PMfinally
block.
I often log timing, exceptions and cancelations for a block of code. With the current approach I’d have to duplicate logging code in catch
clause(s) and at the end of the try block in the success case. I’d also have to use .also { … }
in the try block to not change the return value.
It would be much easier if I could something like
val start = TimeSource.Monotonic.markNow()
val x = try {
lotsOfLogic()
}
finally { e -> // Throwable?
// complicated logging with or without exception
}
Without:
val start = TimeSource.Monotonic.markNow()
val x = try {
lotsOfLogic().also {
// complicated logging without exception
}
}
// multiple catch clauses would duplicate logging
catch(e: Throwable) {
// complicated logging with exception
throw e // rethrow needed
}
louiscad
10/16/2020, 10:36 PMMarc Knaup
10/16/2020, 10:39 PMIaroslav Postovalov
10/17/2020, 5:16 AMlouiscad
10/17/2020, 5:31 AMMarc Knaup
10/17/2020, 5:34 AMIaroslav Postovalov
10/17/2020, 5:35 AMlouiscad
10/17/2020, 5:37 AMMarc Knaup
10/17/2020, 5:38 AMlouiscad
10/17/2020, 6:34 AMMarc Knaup
10/17/2020, 11:47 AMlouiscad
10/17/2020, 1:06 PMMarc Knaup
10/17/2020, 1:28 PM