In general, use both, as appropriate.
Quote:
bool D3DEffect::Initialize(...)
See, I would eschew this method entirely in favor of a constructor, and thus exceptions would be the only way to report an error. Using manual initialize/cleanup methods makes it more difficult to take advantage of RAII, one of the best features offered by C++.
Quote:
Should I use return values or exceptions for errors like these?
Only your second example, using exceptions, works reasonably well. The first example only checks the return value of the
last initialize call. Both examples have some pretty glaring faults but they are not directly related to the actual checking of the error condition, aside from the aforementioned issue, so I will ignore them.
In this case I would prefer the exception method anyhow.
There are no firm rules, but there are guidelines you can follow. Generally, you should prefer exceptions for things that are quite unexpected or out of the ordinary -- things that should not happen during nominal execution. Failure to initialize a complete subsystem is rather abnormal, and thus exceptions should be used.
In contrast, some other things shouldn't use exceptions. Hit testing, for example, is expected to "fail" often during execution and so shouldn't use an exception to report that failure. Similarly, loading a texture from a delay-load cache may "fail" in a fashion that isn't critical, returning a dummy texture until the real texture gets pulled in (for example).
Another way to look at the problem is whether or not the failure would be one the caller of the function can reasonably be expected to handle. This generally involves looking at the problem from a broader perspective, of course.