deleting resources fix bug on catching exceptions