use feature 'try'; try { do_a_thing(); } catch( $e ) { ... } finally { cleanup(); }