I believe that even though this is an illegal instruction, we should all try to do our best to not break the rules.
The rule of thumb for this problem is that there shouldn’t be any random bits and pieces in the code that will make a user’s life more difficult. But if a user had a really bad habit of calling out what they’re thinking and doing, all you have to do is write an application that will take care of the problem. You can be sure the app will read that person’s name and spell that user’s name. But that’s a bad habit.
Sometimes it’s hard to know where to start, but when you’re trying to figure out what your users mean when they say something, you’ll probably want to use exceptions instead. Sometimes you can just look at the code and think. But the next time you’re looking at the code ask yourself. “Does this code have a catch for this problem?” If not, then write it.
I remember thinking at one point that I could probably figure out how to handle this exception. But then I realized that I would just end up writing code that was a little bit too complicated. So I stopped trying. I think I could have probably got it figured out on my own, but I didn’t.
In fact, a few months ago I did a little research on coding practices and how to write exception handling code. I came across an article about exceptions on CodeProject which is pretty interesting. The article is called “What To Do When You Don’t Know What to Do.
I’d like to say that there is no such thing as an “exceptional” exception. There are simply situations where you want to handle an exception. But, in reality, there aren’t just any exceptions. There are just certain exceptions. For example, there are certain situations where the operating system throws an exception. But, you aren’t supposed to use that exception to do anything in your program. And, in fact, you don’t have to use an exception at all.
There are a large set of things that you want to avoid doing with exceptions, and in this case, you want to avoid calling a function that doesnt exist. But, you want to use an exception to do something. But, you dont have to use an exception to do anything.
Well, the exception you want to use is to do stuff you dont want to do. Your program has a function called exit(). But, exit() is not an example of a function. It’s a function that exists solely to create an exception and call another function. So, if you wanted to call an exception to do something you dont want to do, you would create another exception called exit_something_that_doesnt_exist().
You have an exception that doesn’t exist. But, you dont have to call the exception to do something. You can throw it as an exception if you want.
Except this is what exceptions are for. To be more specific, an exception is a place where you can throw what seems like an unexpected exception, but is in fact an exception (or a derived exception if you are in C++). In this case, you want to throw an exception called Exception: Illegal Instruction. This exception can be used to turn off your code, but you usually want to only do that in a critical section of code that should be stopped.