So I made a basic stack-based virtual machine and a compiler that compiles bytecode for it, but I've run into an issue that I have no idea how to solve.
I need to check for things like dividing by zero and stack overflows and throw runtime errors, but the only way I understand to do this is to use exceptions (I'm doing this in C++), or by writing the ifs myself. But putting ifs all over the place will make the VM really slow.
What is the best way to implement runtime errors that ideally uses no CPU until an actual error is thrown?