warning: unreachable code

14
Feb

This you will see in my code as I like to add a raise instruction whenever there is a program construct that would otherwise allow the code to flow there. This simply means that the line(s) of code will never be executed since it is unreachable.

For example, you may have a case statement that handles a few cases and all others. All cases are expected to return1 on completion. It would look something like this:

1
 

As you can see, any code after the case is unreachable. It is easy to see in this example, but if each statement block within each when is one page, you just won't know without looking at a lot of code first.

Now, why would I put a raise Program_Error there? Simple... suppose that at a later time I add another when case that looks like this:

1
 

Now the program continues after the end case; line. This is bad and I will have no idea unless I have a raise statement. That raise statement will (1) not generate this warning anymore and (2) will stop the program if case C happens and doesn't return as expected.

  • 1. It is, of course, expected that each when statement returns a different result. Otherwise we would expect you to put the return statement after the end case line.
0
Your rating: None