Use try/catch for error handling

Signed-off-by: Ian Macalinao <me@ian.pw>