You sure would have to be more precise about the nature of the "program" you are running.
In general the approach would be to protect a critical calculation which could throw an error by the "on error" command (or "try" in Prime) which could return a string or NaN in case the calculation fails. This return value them can be used in a conditional branch.