function doQuery($query) { if(algo_mal()) { throw new Exception( "algo ocurrio mal" ); }}try { doQuery($sql);} catch( Exception $e ) { //rollback}