add error handling

Add exception throwing and catching