Generalized error check to try catch exception