Better exception handling for import of keys