返回列表 回复 发帖

valgrind and throw

  1. #include <stdexcept>
  2. #include <iostream>
  3. #include <vector>

  4. class ValgrindRuntimeError : public std::exception {

  5.   public:
  6.   /** Takes a character string describing the error.  */
  7.   ValgrindRuntimeError(char s[]) {
  8.     _s=new char[strlen(s)];
  9.     strcpy(_s, s);
  10.   }

  11.   virtual ~ValgrindRuntimeError() throw() {
  12.     delete[] _s;
  13.   }

  14.   /** Returns a C-style character string describing the general cause of
  15.    *  the current error (the same string passed to the ctor).  */
  16.   virtual const char* what() const throw() {
  17.     return _s;
  18.   }
  19.   private:
  20.     char *_s;
  21. };

  22. int main() {
  23.   ValgrindRuntimeError a(std::string("xxxx").c_str());
  24.   throw a;
  25. }
复制代码

                     我是一个呼吸着现在的空气而生活在过去的人
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
                                     我已习惯了孤独,爱上孤独
                                 他让我看清了自我,还原了自我
                             让我再静静的沉思中得到快乐和满足
                                   再孤独的世界里我一遍又一遍
                                   不厌其烦的改写着自己的过去
                                             延伸到现在与未来
                                       然而那只是泡沫般的美梦
                                 产生的时刻又伴随着破灭的到来
                         在灰飞烟灭的瞬间我看到的是过程的美丽
                                      而不是结果的悲哀。。。
返回列表