No thanks.
Posted Nov 10, 2012 21:48 UTC (Sat) by
Cyberax (
✭ supporter ✭, #52523)
In reply to:
No thanks. by nix
Parent article:
Haley: We're doing an ARM64 OpenJDK port!
>Hint, Cyberax: consider a simple RAII object which allocates some memory in its constructor, in two tranches, with a single assignment between.
#include <stdio.h>
#include <memory>
#include <stdexcept>
class tracer
{
public:
tracer() { printf("Constructing\n"); }
~tracer() { printf("Dying\n"); }
};
class tester
{
std::auto_ptr<tracer> t1_;
std::auto_ptr<tracer> t2_;
public:
tester()
{
t1_=std::auto_ptr<tracer>(new tracer());
throw std::runtime_error("Test");
t2_=std::auto_ptr<tracer>(new tracer());
}
};
int main()
{
try
{
tester t;
} catch(const std::runtime_error &ex)
{
//Print exception info
}
return 0;
}
cyberax@cybmac:~/work$ ./a.out
Constructing
Dying
And your point is?
Consider that you have to deal with exactly the same crap if you DO NOT use the exceptions. EVERY function you invoke can cause error conditions (such as out-of-memory).
Now please rewrite my example without exceptions, providing the same level of guarantees and functionality.
(
Log in to post comments)