Does this so what you want? Detecting of returning error in CVX
Note that a CVX error, as try catch is designed to catch. is different than an infeasible problem for which CVX will populate CVX variables with NaN. The approach in my link deals with CVX errors, such as not being DCP-compliant due to input data making a problem instance non-convex.