Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: exceptions and a quote from Bjarne Stroustrup

23 views
Skip to first unread message

Bo Persson

unread,
Dec 5, 2016, 2:17:12 PM12/5/16
to
On 2016-12-05 13:54, Stefan Ram wrote:
> Here is a quote from Bjarne Stroustrup regarding teaching:
>
> »The standard library containers and algorithms and the
> use of exceptions in resource management are examples of
> key topics that are often neglected, or wrongly
> considered advanced.«
>
> I think the wording »the use of exceptions in resource
> management« is slightly odd. Historically, we managed
> resources by calling clean-up functions, and exceptions
> blew that up. In the 80s this problem was often ignored,
> eventually we learned how to adjust everything with RAII,
> which is a very ingenious and beautiful solution which
> was AFAIK invented by Bjarne Stroustrup.
>
> But I'd say that what one should learn is »resource
> management (even in the case of exceptions)«, because our
> primary goal is resource management and exceptions do not
> directly help to accomplish that goal, instead at first
> they are a hindrance, but we learned how to do resource
> management even in the case of exceptions. Or instead of
> »the use of«, one might say, »coping with«, i.e.,
> »coping with exceptions in resource management«.
>

No, why?

If you do

p = new x;

and a constructor of one of x's subobjects throws an exception, all the
resources will be cleaned up by the system. You don't have to do
anything (except perhaps catch the exception somewhere else).

Very neat, and a lot easier than handling this manually.



Bo Persson


0 new messages