Added onException method as example of how to print exceptions.