Fixed error throwing to file.
Added exceptions.