Tiglath said:
We are building a high performance system and suddenly the cost of
using exception has been magnified.
What is the actual cost of having a frequent call inside a try-catch
block when the vast majority of times there will be no exception to
catch?
If you do not use exceptions as return value for one of correct state,
you will have no overhead if no error condition will occur.
This is one of example:
//code without exceptions
movl %esp, %ebp
pushl %ecx
subl $20, %esp
call _test
leave
ret
//the same code with exceptions
movl %esp, %ebp
pushl %ecx
subl $20, %esp
call _test
jmp L28
//catch
call ___cxa_begin_catch
call ___cxa_end_catch
L28:
leave
ret
if no error condition will occur, program with exception will be longer
by one "jump" opcode. Of course, size of program with exception will be
greater, than without, but you can not make size smaller even with
manual control:
if(error_condition){print_error(); return;}
do_any();
will always ne longer then just
do_any();
Compiler even can tell CPU what kind of jump condition has more
priority for anticipatory memory access, if CPU supports it.