Improved exceptions and reporting exceptions for command-line compiler.

Is it ok to fix it in a separate pull request for all my code? It seems a bit out of scope for this pull request.