POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: My first C++ program Server Time
1 Oct 2024 07:23:37 EDT (-0400)
  Re: My first C++ program  
From: Orchid XP v8
Date: 21 Sep 2008 08:06:18
Message: <48d638ba$1@news.povray.org>
Warp wrote:

>   The standard data containers, as well as 'new', throw an exception by
> default when they run out of memory. Also the at() member function of
> some of the containers throws an exception if you try to index out of
> boundaries.
> 
>   If you don't want to throw exceptions in your own code, then it depends
> on what is it that you want to do to signal a condition.
> 
>   The usual way to catch programming errors at runtime is to use
> assertions. For example:
> 
> void foo(int min, int max)
> {
>     assert(min <= max);
> 
>     // rest of the code here
> }
> 
>   If the assertion fails, a message will be printed and the program is
> immediately terminated at that point. Obviously this should only be
> used in situations which are a symptom of a programming error and which
> must be fixed.

Right. So assert() is for stuff that should never happen if the 
programmer is doing their job right. In other words, BUGS.

How about stuff that might ordinarily be expected to not work? E.g., 
parsing strings, looking up keys in dictionaries, etc.

It seems that streams at least signal errors by altering the stream 
object and getting the programmer to call a member function to check 
whether an error condition occurred. Is that a usual C++ idiom?

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.