resultFrom is a nice way to bridge exception throwing code with more controlled results, but catching every exception type is often not what one wants or you may know the exception type that will be thrown. resultFromCatching allow catching a subset of Exeption types.
I've had this extension function in my own code base for a bit now - It gets used fairly often (and is preferred over resultFrom) and I thought it may be wanted in the library itself.
Example
fun DateTimeFormatter.parseResult(dateString: String) = resultFromCatching<DateTimeParseException, _> { parse(dateString) }
resultFrom
is a nice way to bridge exception throwing code with more controlled results, but catching every exception type is often not what one wants or you may know the exception type that will be thrown.resultFromCatching
allow catching a subset ofExeption
types.I've had this extension function in my own code base for a bit now - It gets used fairly often (and is preferred over
resultFrom
) and I thought it may be wanted in the library itself.Example