XLL+ Class Library (6.3)

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:

CopyC++
CXlOper* NORMSINV2_Impl(CXlOper& xloResult, double Probability)
{
    CXlOper xloResult;
//}}XLP_SRC 
 
    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: Returning integer values >>