on 2012 Jul 02 5:28 AM
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;
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:)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
11 | |
10 | |
10 | |
10 | |
8 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.