Hi there, I want to ask a question, is there’s a w...
# koin
b
Hi there, I want to ask a question, is there’s a way to catch an exception that happen during creation of an object inside 
single{}
 ? The reason I’m asking this is because when creating 
EncryptedSharedPreferences
 object using 
single{}
, sometimes it’s throw an Exception, and I want to catch that, prevent the crash app on user side, thanks
t
It might be better to track down the reason of the exception. You should be able to catch the exception when you try to use the dependency, but this would be ugly code. If you can guarantee, that the creation succeeds most of the time, you could declare the factory similar to:
Copy code
single {
  while(true) runCatching {
    return@single EncryptedSharedPreferences(...)
  }
}
But as I stated before, the exception has a reason and a cause which leads you to the actual issue you have. The object creation might just be a symptom of it.
b
I had track down the exception and found the issue tracker that similar to what I faced. and there’s no valid solution from the developer team, so for now I just want to avoid the crash and handle it, until the exception handle by the developer team. And yeah, the exception not always happen, only small amount of user that affected by it
the
while
seems a bit off in your recommendation, that’s look smelly and dangerous at least to me
t
Well, any "solution" you'd apply to your issue will be smelly and dangerous in the end. Maybe a crash is the correct handling of the situation for now.