If I understand correctly, the basic principle of catching error catching is that when a certain expected error occurs, return the result of true / false value or the result of the value itself.

I have a certain expression (test) that checks the text in specific IDs, and the task is that if the text does not match (was different from what I expected), I would catch the error by try / catch .

The question itself is how to correctly put this expression in a try / catch so that if one of the parameters does not match, the error is “caught”:

  private val isDialogRunning: Boolean get() { onView(Matchers.allOf(withId(R.id.titleTextView), ViewMatchers.withText("Warning"))) .check(ViewAssertions.matches(isDisplayed())) return true } 
  • How to determine the error itself? Well, that is, I approximately know what error will take off if there is incorrect data, but how will it be correct to register it in catch?
  • what is the question? - Crazy
  • and what is the question itself? And yes, this is of course holivar, but the exception is not intended for "expected errors", that's why it is an exception ... - pavel

1 answer 1

Exceptions are intended for errors that rarely occur and which the program / library cannot prevent or correct. Exceptions should not be used to organize a normal (without errors) program control flow.

Exceptions are useful if you create a library and cannot understand in advance exactly how errors will be handled. Using exceptions you give the programmer who uses your library the ability to do error handling.