Hi,
I know in principal this is unanswerable as it is be implementation
dependent.I have a code base that is heavily littered with try/catch
clauses (the CASE tool has been set up to put a try/catch round
every member function).
[what's that screaming sound I can here?]
Now I know this is BAD but I just wondered how bad. Will it kill
performance? Eat memory? I don't expect many exceptions to
be thrown.
Or do I need to strip the try/catches out and profile it?
--
Nick Keighley 5 4694
Nick Keighley wrote:
Hi,
I know in principal this is unanswerable as it is be implementation
dependent.I have a code base that is heavily littered with try/catch
clauses (the CASE tool has been set up to put a try/catch round
every member function).
[what's that screaming sound I can here?]
This is bad, not because of performance issues, but because of design
issues. The whole point of exception handling is to deal with
exceptional conditions at the "right" level. Otherwise, most of catch
blocks will simply re-throw the exception. By catching at every
function, you might as well just propagate a return code.
>
Now I know this is BAD but I just wondered how bad. Will it kill
performance?
Possibly, ideally, if you don't throw, it's mminimal.
Eat memory?
other than unnecessary code, no.
Or do I need to strip the try/catches out and profile it?
As always, benchmarking profiling is your best answer to performance
related questions.
On Mar 22, 10:07 am, "Nick Keighley"
<nick_keighley_ nos...@hotmail. comwrote:
Now I know this is BAD but I just wondered how bad. Will it kill
performance? Eat memory? I don't expect many exceptions to
be thrown.
Or do I need to strip the try/catches out and profile it?
If you want to know "how bad," you'd have to profile the code with and
without the try/catch statements, although IMO using try/catch
excessively is more of a design foul than a performance foul.
A few questions to ask yourself:
1. Does it matter? If the program runs "fast enough," do you need to
remove the try/catch statements?
2. If it does matter, how much CPU is the try/catch actually using
relative to other parts of the application? If it's .1% (note: this
is me pulling some number out of my arse) of your total CPU time, I'd
wager there's something else that's more worthy of attention.
red floyd wrote:
Nick Keighley wrote:
>Hi,
I know in principal this is unanswerable as it is be implementation dependent.I have a code base that is heavily littered with try/catch clauses (the CASE tool has been set up to put a try/catch round every member function).
[what's that screaming sound I can here?]
This is bad, not because of performance issues, but because of design
issues. The whole point of exception handling is to deal with
exceptional conditions at the "right" level. Otherwise, most of catch
blocks will simply re-throw the exception. By catching at every
function, you might as well just propagate a return code.
Probably a throwback from Java where you absolutely have to catch or
declare as throwable any and all exceptions that might be thrown beneath
you. It's such a pain in the ass that it wouldn't surprise me at all if
a RAD tool decided to just wrap all functions with try/catch to avoid
the hassle.
>
>> Now I know this is BAD but I just wondered how bad. Will it kill performance?
Possibly, ideally, if you don't throw, it's mminimal.
And if you don't know then it doesn't matter.
>
>Or do I need to strip the try/catches out and profile it?
As always, benchmarking profiling is your best answer to performance
related questions.
Exactly.
Noah Roberts wrote:
red floyd wrote:
>Nick Keighley wrote:
>>Hi,
I know in principal this is unanswerable as it is be implementation dependent.I have a code base that is heavily littered with try/catch clauses (the CASE tool has been set up to put a try/catch round every member function).
[what's that screaming sound I can here?]
This is bad, not because of performance issues, but because of design issues. The whole point of exception handling is to deal with exceptional conditions at the "right" level. Otherwise, most of catch blocks will simply re-throw the exception. By catching at every function, you might as well just propagate a return code.
Probably a throwback from Java where you absolutely have to catch or
declare as throwable any and all exceptions that might be thrown beneath
you. It's such a pain in the ass that it wouldn't surprise me at all if
a RAD tool decided to just wrap all functions with try/catch to avoid
the hassle.
I don't understand what the big deal of declaring what the function can
throw. Without knowing what can be thrown, you can't expect to catch
the exception and do something meaningful with it, can you?
Adrian
--
_______________ _______________ _______________ _______________ _________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ _---_ Q. What are you doing here? _---_ /
\ / | A. Just surf'n the net, teaching and | \ /
\__/___\___ learning, learning and teaching. You?_____/___\__/
\/______[blog:__http://adrians-musings.blogspo t.com/]______\/
Adrian Hawryluk wrote:
Noah Roberts wrote:
>red floyd wrote:
>>Nick Keighley wrote:
Hi,
I know in principal this is unanswerable as it is be implementation dependent. I have a code base that is heavily littered with try/catch clauses (the CASE tool has been set up to put a try/catch round every member function).
[what's that screaming sound I can here?]
This is bad, not because of performance issues, but because of design issues. The whole point of exception handling is to deal with exceptional conditions at the "right" level. Otherwise, most of catch blocks will simply re-throw the exception. By catching at every function, you might as well just propagate a return code.
Probably a throwback from Java where you absolutely have to catch or declare as throwable any and all exceptions that might be thrown beneath you. It's such a pain in the ass that it wouldn't surprise me at all if a RAD tool decided to just wrap all functions with try/catch to avoid the hassle.
I don't understand what the big deal of declaring what the function can
throw. Without knowing what can be thrown, you can't expect to catch
the exception and do something meaningful with it, can you?
That's the point, an intermediate function may not care what a function
it calls throws. The clean up is done higher up the call stack.
--
Ian Collins. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Erik Cruz |
last post by:
Hi.
I have read several articles recommending avoid to raise exceptions when
possible, since exceptions are expensive to the system. Removing code from
Try... Catch blocks can help performance? The following 2 first lines of
code - I think - can't raise exceptions:
Try
Dim str As String
Dim intVar As Integer
|
by: clintonG |
last post by:
Has somebody written any guidelines regarding how to determine when
try-catch blocks should be used and where their use would or could be
considered superfluous?
<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
|
by: STom |
last post by:
I heard someone mention to me that the use of try catch exception handling
is very expensive (in relative terms of slowing an app down) if it is used
frequently. Of course they could not explain why.
Is this true? If so, why?
Thanks.
STom
|
by: cj |
last post by:
Another wish of mine. I wish there was a way in the Try Catch structure
to say if there wasn't an error to do something. Like an else
statement. Try Catch Else Finally.
Also because I understand Finally runs whether an error was caught or
not, I haven't found a use for finally yet.
|
by: tommaso.gastaldi |
last post by:
It would be useful, sometimes, when debugging, to disable
all the try /catch one has in the program (clearly not commenting them
out).
Any info or hint on that?
-tom
| |
by: stktung |
last post by:
Hi,
I'm not too familiar with how exception works in .NET but I've read
from somewhere that in C++, code that are ran in try blocks are
expensive:
http://gamearchitect.net/Articles/ExceptionsAndErrorCodes.html
Is it the same for .NET? or .NET implements a Zero Overhead Exception
Handling (as mentioned in the article) that makes codes ran in the try
|
by: pigeonrandle |
last post by:
Hi,
Does this bit of code represent complete overkill?!
try
{
//create a treenode
TreeNode tn = new TreeNode();
//add it to a treeview
tv.Nodes.Add(tn);
|
by: yinglcs |
last post by:
I read the document here about exception handling in python:
http://www.diveintopython.org/file_handling/index.html
Can you please tell me how can I catch all exception in python?
like this in Java:
try {
....
} catch (Throwable t) {
...
|
by: gnewsgroup |
last post by:
We all seem to know that database connections are expensive and we try
to reduce the number of database trips as much as possible.
This may sound like a stupid question: What makes a database
connection expensive? Is it memory intensive? CPU-intensive? Or does
it use a lot of bandwidth? Or none of these?
Thanks.
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |