2015-07-21 132 views
0

的运行下面的代码仍然产生到stdout(不是标准错误)虽然异常被成功捕获一条错误消息:犰狳如何摆脱错误信息

Mat<double> matrix_quantiles(const vector<double> & quantiles, 
         const Mat<double> & m) { 
    Mat<double> sorted_matrix; 
    try { 
    sorted_matrix = arma::sort(arma::cor(m)); 
    } catch(std::logic_error & e) { 
    /* 
    Sometimes a col is constant, causing the correlation to be 
    infinite. If that happens, add normal random jitter to the 
    values and retry. 
    */ 
    const Mat<double> jitter = Mat<double>(
    m.n_rows, m.n_cols, arma::fill::randn); 
    return matrix_quantiles(quantiles, 1.e-3 * jitter + m); 
} 
etc. 

的错误信息是:

error: sort(): given object has non-finite elements 

代码运行良好,抖动策略足以满足我的要求,但如果将输出写入stdout,则必须过滤掉错误消息。

谢谢。

回答

1

要禁用打印错误信息,请在包含Armadillo标头之前定义一个名为ARMA_DONT_PRINT_ERRORS的宏。例如:

#define ARMA_DONT_PRINT_ERRORS 
#include <armadillo> 
+0

有关配置Armadillo的更多信息,请参见[documentation](http://arma.sourceforge.net/docs.html#config_hpp) – mtall