try and catch

E

Ernst Sauer

Hello,

it seems to me, that try and catch is (very?) expensive in time.
Is it?

Thanks
Ernst
 
A

Arne Vajhøj

it seems to me, that try and catch is (very?) expensive in time.
Is it?

Try catch without an exception should cost very little in
execution time.

Try catch with an exception cost some in execution time.

But as the name indicates then exceptions are intended for
situations that are exceptional. By definition something
exceptional should not be relevant for overall application
performance.

Let us take an example.

You reading 1 billion lines of text each with a number
and parsing them.

You decide to use exceptions for error handling.

If the file is good and no exceptions are throw, then
all is fine. No significant overhead.

If the file is garbage and do not contain numbers
then it depends on your code.

If your code catch the exception, display an error
message to the user and exit - then no performance
problem.

If your code catch the exception, increment a counter
and the continue to next line - when last is read and processed
notify the user of the number of errors and exit - then trowing and
catching 1 billion exceptions will be very significant.

But I would blame that on the code not on the
exception mechanism.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Try Catch Exception 14
cpp-Dialog --> C#-Dialog 2
open a men without a click 5
Try Catch 2
need a simple animation tool 2
Help with Try/catch 4
Weird exception behavior 2
try-catch question 5

Top