[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: PCB head fails with ***MEMORY-ERROR***
On Mon, 6 Jun 2011 11:29:57 -0700
Andrew Poelstra <asp11@xxxxxx> wrote:
> On Mon, Jun 06, 2011 at 11:00:51AM -0700, Colin D Bennett wrote:
> >
> > I do: C++. Automatic destruction is your friend.
> >
> > <ducks and runs> :-)
> >
>
> Maybe for memory -- but for more complex resources this
> doesn't work in C++ because there is no way to signal
> errors from a destructor.
>
> In fact, if a destructor throws an exception while the
> stack is being unwound for a different exception, C++
> will get confused and simply kill your program.
Of course. It is critical that destructors never throw exceptions.
Anyway, I thought we were talking about memory in this case. Memory is
by far the most common and critical resource to manage.
Even for other resources (network socket, file descriptor, etc.) you
can at very least perform a best effort to release the resource and
prevent leaks. You could call a dispose() function in the usual case,
but at least having a destructor to clean up in case there is, for
instance, a âreturnâ inside a loop acts as a safety net to prevent
leaks.
Supposing it was âgoodâ to throw exceptions from destructors, then what
would you even do with the exception or error event?
- Just log it? (Do this directly in the destructor; don't throw.)
- Abort the higher level operation? (No need to abort, you were
done with the resource anyway.)
Regards,
Colin
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user