I don't want to contradict Hennessy and Patterson, but you can definitely trap invalid instructions in application code!
for example, say you want to determine if a computer has SSE. You simply query CPUID and check a status bit. But what if the CPU doesn't support the CPUID instruction (486 and below, and Cyrix 686s don't). Then you'll get an invalid opcode exception raised.
You get around that by using a try/catch exception handling block in C++, for example.
The code :
__try {
__asm xor eax, eax
__asm xor ebx, ebx
__asm xor ecx, ecx
__asm xor edx, edx
__asm cpuid
}
__except (EXCEPTION_EXECUTE_HANDLER) {
cerr << " CPU does NOT have CPUID capability!";
return;
}
does the trick.