Hi Guys,

What is the scope of the exception variables when I catch them by reference.

try{
   throw AnExceptionObect("Exception message");
}
catch(AnExceptionObect &exp){
logger << exp.what(); //logger is a dummy object
throw; //what will happend now? is it going to be throwen by value? and what if I catch this object on seperate module/so/dll as reference again?
}

Thanks in advance.

S

What is the scope of the exception variables when I catch them by reference.

I think you mean what is the lifetime of exception objects. Because the scope is a trivial question: the scope of an exception variable, whether caught by value, pointer, or reference, is the catch block.

The lifetime of an exception object is more interesting, but the simplest "mostly correct" answer is that the object lives as long as there's a handler for the exception.

Edited 5 Years Ago by Narue: n/a

Thanks for the reply.

The lifetime of an exception object is more interesting, but the simplest "mostly correct" answer is that the object lives as long as there's a handler for the exception.

If what you are saying is correct, that means runtime system always have to push the current exception list on the heap to keep track what it can handle, so can we conclude handling exception make the program slower as it always have to do a check on a heap?

runtime system always have to push the current exception list on the heap to keep track what it can handle

That's one possibility, but it's not required.

so can we conclude handling exception make the program slower as it always have to do a check on a heap?

You can conclude that the use of exceptions does involve some overhead, but your reason is a little simplistic. There are a number of factors involved in the performance of exceptions.

This question has already been answered. Start a new discussion instead.