Why do I need the Unreachable statement error?

Why does the compiler throw this error? What's wrong with the code not executing??

Author: Alex, 2019-12-03

2 answers

The compiler throws this error to warn the programmer that the given code will never be executed. This is necessary so that there are no problems in the case when you expect the execution of a given line, but it is not reached.

We can say that we are protected from a potential error that may occur as a result of the fact that the written code is not executed.

 4
Author: Altusha, 2019-12-06 05:15:02

If this was not an error, but a warning (who reads warnings at all?), or it was not reported at all, then you might accidentally insert return in the wrong place, and wonder why your code does not work as you expect.

If you (now) do not need the code to be executed, comment it out or put the code block in a separate method.

 1
Author: insolor, 2019-12-05 05:54:34