Adding exception handling and test for it