Stuart’s MATLAB Videos

Watch and Learn

Using otherwise to throw errors in a switch case

In some code there is an enumerated set of choices. People will use a switch case statement to check for all but one choice and then catch that last one in the ‘otherwise’ block of their code. However, if there is unexpected inputs, the ‘otherwise’ will fire when it should not.

This video shows a technique for catching this problem. It is important to catch these errors from unexpected inputs immediately, because they can have effects on your code much farther down the line. When this happens, it would be hard to trace back to the cause.

|
  • print

评论

要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。