l33773l
l33773l

Reputation: 39

Kotlin/Android app crashes without a Stack Trace

I've encountered a situation where anything that runs in a coroutine (database queries, network requests or response processing) and fails at some point, simply crashes the app without any logs at all. Is it the expected behavior or do I have something misconfigured?

Here's a simple piece of code that reproduces the error. Nothing changes with different Dispatchers.

Code

This is the only output I'm getting, followed by app termination

Output

And these are the dependencies I'm using, the latest version at the moment of writing.

Dependencies

It's also reproducing in a simple CLI app without the Android framework.

Edit: Just to make it clear. I'm not trying to see the Exceptions that I'm throwing. I'm trying to get some output when my app crashes because of an unknown reason.

Edit2: To add some clarity, here is another example of the situation without any "throw" statements.

Scenario 2

Output 2

Upvotes: 1

Views: 457

Answers (1)

apksherlock
apksherlock

Reputation: 8371

Since the exception in happening inside the coroutine, it makes sense to find it there also. Just surround it with try/catch and you will see the magic:

GlobalScope.launch{
  try{
   print("Your printing message")
   throw Exception("Message here")
  }catch(exception: Exception){
   exception.printStacktrace()
   }
 }

Upvotes: 1

Related Questions