Added a missing header and fixed exceptions to be portable.