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... )
begin
    ...code...
exception
    when ...specific-exception... then
        ...handle-specific-exception...
    when others then
        -- log general error
        resignal;
end;

asked 02 Jul '12, 04:28

Volker%20Barth's gravatar image

Volker Barth
40.2k361549822
accept rate: 34%

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
40.2k361549822
accept rate: 34%

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×275
×7

question asked: 02 Jul '12, 04:28

question was seen: 1,790 times

last updated: 03 Jul '12, 03:41