Error handling in C++, constructors vs. regular methods
<p>I have a <code>cheesesales.txt</code> CSV file with all of my recent cheese sales. I want to create a class <code>CheeseSales</code> that can do things like these:</p>

<pre><code>CheeseSales sales("cheesesales.txt"); //has no default constructor
cout &lt;&lt; sales.totalSales() &lt;&lt; endl;
sales.outputPieChart("piechart.pdf");
</code></pre>

<p>The above code assumes that no failures will happen. In reality, failures will take place. In this case, two kinds of failures could occur:</p>

<ul>
<li>Failure in the <strong>constructor</strong>: The file may not exist, may not have read-permissions, contain invalid/unparsable data, etc.</li>
<li>Failure in the <strong>regular method</strong>: The file may already exist, there may not be write access, too little sales data available to create a pie chart, etc.</li>
</ul>

<p>My question is simply: How would you design this code to handle failures?</p>

<p>One idea: Return a <code>bool</code> from the regular method indicating failure. Not sure how to deal with the constructor.</p>

<p>How would seasoned C++ coders do these kinds of things?</p>
