Improved error formatting and added custom exception.