cancel
Showing results for 
Search instead for 
Did you mean: 

How big is the performance impact for error handling in case no error occurs?

VolkerBarth
Contributor
2,117

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;
VolkerBarth
Contributor
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

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:)

Answers (0)