The forum will be unavailable for maintenance at some point from Friday, April 13 at 19:00 EDT until Sunday, April 15 at 23:59 EDT. Downtime will be minimized but the exact timing is unknown.

Preface: This was asked in a comment in the following FAQ, and I think it deserves its own topic:

How big is the performance impact for error handling for a procedure/function call in case no exception does occur - compared to omitting the exception handler?

In other words: If I don't really expect any possible exception but would add a general exception handler like the following, do I have to pay a noticeable "amount of runtime performance" for this means of defensive programming?

Or does it cope, say, with C++'s goal of "You don't pay for what you don't need"?

procedure foo( ...parameters... )
    when ...specific-exception... then
    when others then
        -- log general error

asked 02 Jul '12, 04:28

Volker%20Barth's gravatar image

Volker Barth
accept rate: 32%

edited 02 Jul '12, 09:36

@Breck, @Elmi, @Mark: You're invited to answer this here again:)

(02 Jul '12, 04:32) Volker Barth

To cite Elmi Eflov from the other FAQ:

Exception handling has almost no overhead unless the exception handler is invoked.

and Mark added:

[...] there is very little overhead. The only time there is any effect is when the procedure is initially parsed which is done when the procedure is invoked for the first time. Beyond that the existence of the exception handler is nil... until it is invoked.

As a consequence, there is no performance reason not to add a general exception handler:)

permanent link

answered 03 Jul '12, 03:41

Volker%20Barth's gravatar image

Volker Barth
accept rate: 32%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 02 Jul '12, 04:28

question was seen: 830 times

last updated: 03 Jul '12, 03:41