R
Rennie deGraaf
Is it better/more efficient to throw exceptions by value, as in
void func() throw (SomeException)
{
// do some stuff
throw SomeException("error message");
}
void bar()
{
try
{
foo()
}
catch (SomeException e)
{
// do some stuff
}
}
or by reference, as in
void func() throw (SomeException*)
{
// do some stuff
throw new SomeException("error message");
}
void bar()
{
try
{
foo()
}
catch (SomeException* e)
{
// do some stuff
delete e;
}
}
? Either method requires allocating memory (on the stack in the first
case, on the heap in the second), so I don't think that either is any
less safe than the other. Obviously, the method of throwing pointers is
prone to memory leaks if programmers are not careful, but is it any more
or less efficient?
Rennie
void func() throw (SomeException)
{
// do some stuff
throw SomeException("error message");
}
void bar()
{
try
{
foo()
}
catch (SomeException e)
{
// do some stuff
}
}
or by reference, as in
void func() throw (SomeException*)
{
// do some stuff
throw new SomeException("error message");
}
void bar()
{
try
{
foo()
}
catch (SomeException* e)
{
// do some stuff
delete e;
}
}
? Either method requires allocating memory (on the stack in the first
case, on the heap in the second), so I don't think that either is any
less safe than the other. Obviously, the method of throwing pointers is
prone to memory leaks if programmers are not careful, but is it any more
or less efficient?
Rennie