create custom exception/error handling mechanism

As a follow up from #177