Here there is such a code

return Observable.just(new Date())// .map(// iEndDate -> { Date latestDate = (Date) mEmployeeCallsByDate.keySet().toArray()[mEmployeeCallsByDate.size() - 1]; if (latestDate.after(iEndDate)) { return latestDate; } return iEndDate; }// )// .blockingFirst(); 

How can you catch a mistake? Let's say nalpointer

If you use subscribe() instead of blockingFirst then you can subscribe to an error, and then how?

  • What is the meaning of this code? - Sviat Volkov
  • @SviatVolkov Just checking, you need to return either the latestDate or endDate , according to the condition - Aleksey Timoshchenko

1 answer 1

Here, something like this.

  Observable.just("") .map { //тут просто произошло что-то плохое throw RuntimeException() return@map "" } .onErrorReturn { //пишем в лог и подсовываем что захотим Timber.e(it) return@onErrorReturn "" } .blockingFirst() 
  • The question is not on the topic, but how to check the instanse of ? Just cast and if it didn't work then catch the error? But it happens when there are several checks, when we check once if it is an instance, if not, then we check if it is another, what to do in this case? - Aleksey Timoshchenko February
  • Just like with ordinary exceptions, Throwable comes to onErrorReturn, you can check through the instance of, and then work as with a specific exception. - Kota1921