Re: Constructors And Exceptions

From: Siemel Naran (SiemelNaran_at_REMOVE.att.net)
Date: 12/16/04


Date: Thu, 16 Dec 2004 04:41:57 GMT


"Kurt Krueckeberg" <kurtk@pobox.com> wrote in message
news:G8adnWKVLp2jP13cRVn-

> class Sample {
> public:
> Sample()
> {
> s_ = new char[5];
> throw;
> }
> private:
> auto_ptr<char *> s_; // destructor will free memory if
exception
> is thrown
> };

The type of s_ is like char**, so your could should not compile. Anyway,
even if you use auto_ptr<char>, the code will compile but it is not correct,
because one must use delete[] to delete arrays. I think the appropriate
container here is std::vector, though I think boost has an auto_ptr like
object that invokes delete[].



Relevant Pages

  • Re: ArgumentOutofRangeException in ListView
    ... > With a little reworking of the code, I was able to get this to compile; ... exception to be thrown. ... and debug it step by step to see where exactly the exception is being ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: How to debug this?
    ... >> When you compile a program in 'debug' configuration these 'symbols' are ... >> allow for richer information to be displayed when an exception occurs. ... >> is thrown ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Delphi 7 vs Delphi 2005
    ... > The problem is it dies during the compile and no exception is thrown. ... I suggest removing sections of code until it compiles OK, ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: is catch and re-throw a good idea?
    ... >>catching a Throwable doesn't stop the exception from being a MyException ... > The below code doesn't compile because ... declared to be thrown ...
    (comp.lang.java.programmer)
  • Re: Possible reasons for a C++ exception being thrown for line three?
    ... kind of exception was thrown, and by whom, and what line ... debugger, then it throws the exception. ... char String2MATCH; ...
    (microsoft.public.vc.mfc)