I just threw together a quick exception handling class, and when I use it, I'm getting an error for some odd reason.
Here's the code:
vectorexception.h
Code:#ifndef VECTOREXCEPTION_H_ #define VECTOREXCEPTION_H_ class VectorException { protected: char *error; public: VectorException(); VectorException(const char *); ~VectorException(); char *getError(); }; #endif
vectorexception.cc
main.ccCode:#include <cstring> #include "vectorexception.h" VectorException::VectorException() { error = new char[sizeof(char) * strlen("No error message specified.")]; strcpy(error,"No error message specified."); } VectorException::VectorException(const char *error) { this->error = new char[sizeof(char) * strlen(error)]; strcpy(this->error,error); } VectorException::~VectorException() { delete[] error; error = NULL; } char *VectorException::getError() { return error; }
And the error:Code:#include <cstdio> #include "vectorexception.h" int main(void) { try{ throw VectorException("oh noes"); } catch(VectorException e) { printf("%s\n",e.getError()); } return 0; }
I'm using GCC, and compiling with the flags -MMD -ansi -Wall -pedantic.Code:oh noes *** glibc detected *** double free or corruption (fasttop): 0x0805f158 *** Aborted



LinkBack URL
About LinkBacks


