Added std::exception handling