Re: Exception Misconceptions: Exceptions are for unrecoverable errors.
In article <hgskgk$kc2$1@news.albasani.net>, Vladimir Jovic <vladaspams@gmail.com> wrote:
James Kanze wrote:
On Dec 22, 4:55 pm, Kaz Kylheku <kkylh...@gmail.com> wrote:
On 2009-12-22, Vladimir Jovic <vladasp...@gmail.com> wrote:
Stefan Ram wrote:
[snip]
More elegantly? Actually, for correct and secure C++
code, all functions need to be written to be ?exception
safe?, but only a minority of C++ programmers does so or
even is aware of it.
Why?
The above is false. Exception-safe code is needed to write
code that avoids resource leaks in the face of an exception.
It's need to write code that is correct in the face of an
exception. What "correct" means depends on the application
specifications. (On the other hand, what he wrote is false in
so far that if the function calls no other function, or only
calls functions guaranteed not to throw, it doesn't have to be
exception safe.)
Ok, I forgot about that. Thank you.
But how many people are adding what exception can a method throw in it's
declaration? (forgot how it is called. Is it exception declaration?)
All normal coding styles are telling that is causing more trouble then
it helps.
For instance:
{
char *p = new char[256];
f();
}
If f throws an exception, this statement block is abandoned,
and the allocated memory is leaked.
Or not. If the application is using garbage collection, it's
not leaked. If the application immediately terminates (and is
in a hosted environment), it's not leaked.
Not many people are using GC :P
I recall seeing some articles on gc issue in C++ a while back
on this very group. Do not remember what it was.
But what can I say out of my own experience with Java is this:
A well written GC is such a help, that I can not even see the
argument of not implementing it to this day.
I bet you can not even imagine how much times was wasted to date
by the programmers to deal with this totally stoopid issues
related to memory deallocation. Probably at least 30% of total
time spend on developing the C++ code.
C++ would probably be benefited tremendously if it adopted some
of the central Java concept, such as GC, threads and GUI.
Except that would require an equivalent of a virtual machine
underneath.
And that is one of central issues with Java.
I even had a long argument AGAINST JVM a while back
on the basis of program fat. JVM takes at least 10-20 megs
of memory to even run a program. But, by todays standards,
it is not even worth mentioning since almost any modern
program takes hundreds of megs of memory to run, and the
JVM load time is negligeable compared to run time of any
more or less complex application.
So, there you have it...
--
Programmer's Goldmine collections:
http://preciseinfo.org
Tens of thousands of code examples and expert discussions on
C++, MFC, VC, ATL, STL, templates, Java, Python, Javascript,
organized by major topics of language, tools, methods, techniques.