<p>I know most people think that as a <em>bad practice</em> but when you are trying to make your class public interface only work with references, keeping pointers inside and only when necessary, I think there is no way to return something telling that the value you are looking doesn't exist in the container.</p>

<pre>
class list {
    public:
        value &get(type key);
};
</pre>

<p>Let's think that you don't want to have dangerous pointers being saw in the public interface of the class, how do you return a not found in this case, throwing an exception?</p>

<p>What is your approach to that? Do you return an empty <em>value</em> and check for the empty state of it? I actually use the throw approach but I introduce a checking method:</p>

<pre>
class list {
   public:
      bool exists(type key);
      value &get(type key);
};
</pre>

<p>So when I forget to check that the value exists first I get an exception, that is really an <em>exception</em>.</p>

<p>How would  you do it?</p>

Interesting question. It's a problem in C++ to exclusively use references I guess - in Java the references are more flexible and can be null. I can't remember if it's legal C++ to force a null reference:
```
```
MyType *pObj = nullptr;
return *pObj
```
```
But I consider this dangerous. Again in Java I'd throw an exception as this is common there, but I rarely see exceptions used so freely in C++.
If I was making a puclic API for a reusable C++ component and had to return a reference, I guess I'd go the exception route.
My real preference is to have the API return a pointer; I consider pointers an integral part of C++.