Catching exceptions by reference and freeing memory before returning.