XLL+ Class Library (7.0)

Throwing exceptions

Another useful technique for handling errors is to throw an exception of type CXlErrorException. This has the same effect as setting xloResult to an error value, and allows more natural C++ program flow.

For the previous example, throwing an exception would result in code like this:

CXlOper* NORMSINV2_Impl(CXlOper& xloResult, double Probability)
    CXlOper xloResult;
    double Z;                                
    if (!InverseCumNormal(Probability, &Z))  
        throw CXlErrorException(xlerrNum);   
    xloResult = Z;                           
    return xloResult.Ret();

Particularly when there are many possible avenues to failure, this approach leads to more transparent and reliable code.

Next: A function with a vector argument >>