Question: Say, I want to create a File class

```
class File{
    public:
          File(const char *file){
               openFile(file);
          }
          ~File();
          isEmpty();
};

```

openFile checks if the file exists or if the contents of the file are valid or not.

```
File *file = new File("filepath");
if(file)
file->isEmpty();

```

if my filepath is correct, then all fine, file instance is proper and we can invoke `file->isEmpty();`
What is the file does not exist, in that case still the check `if(file)` evaluates to true and will lead to creation of file instance which is actually invalid. How can i guarantee that if file path is invalid, the file instance should be null.

Answer: 
The only way to do checking like that in the constructor is to throw an exception. But that's not considered good design - you should create it, check if it's valid, and delete it if it isn't.
I would use the STL, templates and throw an empty class. Now, you can't return anything from a constructor... so either do something like this:

```
#include <string>
using std::basic_string;

class EmptyFile{};

template<typename T>
    class File
    {
    public:
        File(const basic_string<T> &FILE)
        {
            if (isEmpty(FILE)) throw EmptyFile();
            openFile(FILE);
        }
        bool isEmpty(const basic_string<T> &FILE) const
            { return FILE.empty(); }
    };

```

or you could do this:

```
#include <string>
using std::basic_string;

template<typename T>
class File
{
public:
    bool Open(const basic_string<T> &FILE) const
    {
        bool empty = isEmpty(FILE);
        if(!empty)
           /* open the file */;
        return isEmpty;
    }
    bool isEmpty(const basic_string<T> &FILE) const
    { return FILE.empty(); }
};

```