Catching errors in the main controller code