std::runtime except

来源:互联网 发布:js图片切换效果代码 编辑:程序博客网 时间:2024/06/07 20:47
 

class DataException:public std::runtime_error{
 public:
  /// <summary>
  /// Initializes a new instance of a DataException.
  /// </summary>
  /// <param name="message">The error message.</param>
  DataException(const std::string & message)
   :std::runtime_error(message){}

  /// <summary>
  /// Initializes a new instance of a DataException.
  /// </summary>
  /// <param name="message">The error message.</param>
  /// <param name="details">Error details to be appended to the message.</param>
  DataException(const std::string & message , const std::string & details)
   :std::runtime_error(message+": "+details){}
 };

 

 

static void NotEmpty(const std::string & value, const std::string & message="String is empty error."){
   if(value.length()==0){
    throw DataException(message);
   }
  }