Adding permission check and error throw in C++