#include <iostream>
#include <memory>
using namespace std;

class Object {
    public:
};

struct Exception {};

struct Wrapper {
	Object *ptr = nullptr;
	Object& operator *() {
		if(ptr == nullptr)
			throw Exception();
		else
			return *ptr;
	}
};

int main() {
	unique_ptr<Wrapper> up = make_unique<Wrapper>();
	unique_ptr<Wrapper> up2 = make_unique<Wrapper>();
	up2->ptr = new Object();
	try {
		Object& refToValid = **up2;
		cout << "Dereferenced" << endl;
		Object& ref = **up;
	} catch(Exception& e) {
		cout << "Exception" << endl;
		delete up2->ptr;
	}
	return 0;
}