adding error messages, fixing bad use of throw()