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.
- Category:
- Format: Video,
- Level: Basic
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.