added proper exception handling

Signed-off-by: duketwo <duketwoqq@gmail.com>