exception handling as per @michaelhelmick