more defensive exception handling