better way of handling exception