Capture unauthorizedaccessexception properly