| re: Will this leak ? (question on throw statement)
Bit byte wrote:
[color=blue]
> I have a simplistic exception class like so:
>
> class CommException {
> public:
> CommException(const char *err){ strncpy(msg,err,ERR_MSG_LEN); }
> virtual ~CommException(){;}
> void erase(void) { memset(msg,'\\0',ERR_MSG_LEN); }
> const char* report(void) { return msg ; }
>
> private:
> CommException( const CommException&);
> CommException& operator= (const CommException&) ;
>
> char msg[ERR_MSG_LEN+1] ;
> };
>
>
> When I use this kinda statement:
>
> throw CommException("Blah, blah, blan") ; //compiler barfs here
>
> Unless I do this:
>
> throw new CommException("Blah, blah, blah") ;
>
>
> In my catch statement, I have this:
>
> catch (const CommException& e) {
> //do something with e
> //recvd const *ref*, so I cant 'delete' (maybe this is a an
> example of a time that one NEEDS to receive an exception by a pointer?
> }
>
> Since I am using the *new* keyword (I still don't know why my compiler
> insists on this), I assume I am alloc'ing memory from the heap rather
> than the stack - so do I need to free this in my catch statement?
>
>[/color]
Just been doing some further reading (thanks to parashift), and I
strongly suspect my compilers insistence on the new keyword is related
to my hidden copy constructor in the CommException class ... (please
correct me if I'm headed down the wrong path though) |