I have two pieces of code performing virtually the same task. While one of
them (f1) is written in a try block, hoping to catch as many exceptions as
possible, the other one (f2) is not:

void f1 (void)
{
try
{
do_task1();
do_task2();
do_task3();
}
catch (exception1){...}
catch (exception2){...}
...
}

void f2 (void)
{
do_task1();
do_task2();
do_task3();
}

Does f1 imposes any necessary runtime-overhead? Is to answer this question
implementation dependent? And if so, is there a general answer applies to
most implementations?

ben

Re: try block performance by Carl

Carl
Sun Feb 29 22:50:32 CST 2004

benben wrote:
> I have two pieces of code performing virtually the same task. While
> one of them (f1) is written in a try block, hoping to catch as many
> exceptions as possible, the other one (f2) is not:
>
> void f1 (void)
> {
> try
> {
> do_task1();
> do_task2();
> do_task3();
> }
> catch (exception1){...}
> catch (exception2){...}
> ...
> }
>
> void f2 (void)
> {
> do_task1();
> do_task2();
> do_task3();
> }
>
> Does f1 imposes any necessary runtime-overhead?

Yes, sometimes. It does in VC.

> Is to answer this
> question implementation dependent?

Yes. Some implementations of EH suffer 0 runtime impact in the
non-exceptional case.

> And if so, is there a general
> answer applies to most implementations?

No. You might want to take a look at the C++ Committee's report of C++
performance. http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/PDTR18015.pdf

-cd