星星博客's Archiver

cnangel 发表于 2012-7-25 10:54

valgrind and throw

[code]#include <stdexcept>
#include <iostream>
#include <vector>

class ValgrindRuntimeError : public std::exception {

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

  virtual ~ValgrindRuntimeError() throw() {
    delete[] _s;
  }

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

int main() {
  ValgrindRuntimeError a(std::string("xxxx").c_str());
  throw a;
}[/code]

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2009 Comsenz Inc.