mbonnin
03/01/2019, 10:36 AMcatch
clauses. For an example IOExceptions on files/connections that made the app crash while we should have just shown an error screen.
We were considering removing exceptions altogether from our codebase and just rely on return values. Legacy java dependencies like File
would still need catch
blocks and that's okay. But then we realized that even new libs like retrofit-coroutines throw exceptions.
How are you handling this ? Do you have a lot of exception handling in your codebases or do you use return values ? Is it okay for kotlin libs to throw non-fatal exceptions ?tddmonkey
03/01/2019, 10:38 AMmbonnin
03/01/2019, 10:39 AMmbonnin
03/01/2019, 10:40 AMonError
handling is that it eats fatal programming mistakes silently. Fatal and non-fatal exceptions are handled the same way.tddmonkey
03/01/2019, 10:41 AMPublisher
interface where possibletddmonkey
03/01/2019, 10:41 AMmbonnin
03/01/2019, 10:42 AMonError
the same way as a non-fatal recoverable one (a HTTP error)tddmonkey
03/01/2019, 10:43 AMtddmonkey
03/01/2019, 10:44 AMmbonnin
03/01/2019, 10:47 AMonError
, you need to explicitely check the type of the exception (sorry for the RxJava reference, I don't know much about spring reactor). And knowing in advance what kind of exception might be encoutered is hard as the chain becomes longuermbonnin
03/01/2019, 10:51 AMlongChainOfObservable.subscribe({}, {displayErrorScreen()})
or
2. longChainOfObservable.subscribe({}, {e->
when (e) {
is HttpException -> displayErrorScreen()
else throw Exception("unhandled exception in stream", e)
}
})
mbonnin
03/01/2019, 10:52 AMSSLSocketException
or FileNotFound
, ...tddmonkey
03/01/2019, 10:58 AMtddmonkey
03/01/2019, 10:59 AMhttpObservable.doOnError(.... things to handle errors)
, which will catch ALL errors, before returning to the top.mbonnin
03/01/2019, 11:01 AMonError
handler in the end, right ? Because all exceptions would have been handled earlier in the chain ?tddmonkey
03/01/2019, 11:01 AMlongChainOfObservable
could never see HttpException
, it would see some domain exception I inventmbonnin
03/01/2019, 11:01 AMtddmonkey
03/01/2019, 11:01 AMmbonnin
03/01/2019, 11:05 AMlib.doCall()
can throw a IOException
. With kotlin this is not true anymore. If lib.doCall()
throws and you forget to add handling code, your app crashes 😕mbonnin
03/01/2019, 11:06 AMlib.doCall()
can actually throwsitepodmatt
03/01/2019, 11:06 AMtddmonkey
03/01/2019, 11:07 AMmbonnin
03/01/2019, 11:07 AMsitepodmatt
03/01/2019, 11:08 AMmbonnin
03/01/2019, 11:10 AMsitepodmatt
03/01/2019, 11:10 AMtddmonkey
03/01/2019, 11:11 AM@SneakyThrows
on most things and treated checked as unchecked exceptionsmbonnin
03/01/2019, 11:11 AMcatch
and if you omit it your app crashes. That's valuable information.tddmonkey
03/01/2019, 11:13 AMRuntimeException
could still be thrownmbonnin
03/01/2019, 11:14 AMmbonnin
03/01/2019, 11:15 AMsitepodmatt
03/01/2019, 11:16 AMmbonnin
03/01/2019, 11:16 AMtddmonkey
03/01/2019, 11:16 AMRuntimeException
== unchecked exceptiontddmonkey
03/01/2019, 11:17 AMRuntimeException
doesn’t need to be explicitly handled by the caller, a checked exception does.tddmonkey
03/01/2019, 11:18 AMmbonnin
03/01/2019, 11:18 AMmbonnin
03/01/2019, 11:18 AMtddmonkey
03/01/2019, 11:18 AMmbonnin
03/01/2019, 11:19 AMtddmonkey
03/01/2019, 11:20 AMmbonnin
03/01/2019, 11:20 AMmbonnin
03/01/2019, 11:21 AMmbonnin
03/01/2019, 11:21 AMmbonnin
03/01/2019, 11:22 AMmbonnin
03/01/2019, 11:22 AMmbonnin
03/01/2019, 11:23 AMtddmonkey
03/01/2019, 11:33 AMcom.amazonaws.SdkClientException
. These actually have a method on them to let you know if it’s a retryable (recoverable) error or notmbonnin
03/01/2019, 11:34 AMmbonnin
03/01/2019, 11:44 AMtddmonkey
03/01/2019, 11:51 AMmbonnin
03/01/2019, 12:05 PMtddmonkey
03/01/2019, 12:11 PMmbonnin
03/01/2019, 12:28 PMGo was initially released with exception handling explicitly omitted, with the developers arguing that it obfuscated control flow.[16] Later, the exception-like panic/recover mechanism was added to the language, which the Go authors advise using only for unrecoverable errors that should halt the entire process.
Looks like I should switch to golang 🤔