Improved error handling: converted all exits to std::exceptions