Stumbled on some old code that is throwing and empty catching some cast exceptions (about 20 per trip :( )
What if any is the performance hit were taking due to this? Should I be worried about this or is the overhead simply in the try / catch
Surprisingly lacking information on the topic of exception performance with C#.
Thanks, from yours truly.
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
The exceptions are going to slow you down more than most average lines of code. Instead of casting and then catching the exception, do a check instead. For example
BAD
myType foo = (myType)obj;
foo.ExecuteOperation();
GOOD
myType foo = obj as myType;
if (foo != null)
{
foo.ExecuteOperation();
}
That's bad for two reasons.
If they're just try { } finally { }
groups, then it's all good -- there's no overhead there. However, try { } catch { }
is both potentially dangerous and potentially slow.
As for documentation, this is pretty good: http://www.codeproject.com/KB/architecture/exceptionbestpractices.aspx#Don%27tuseexceptionhandlingasmeansofreturninginformationfromamethod18
Edit: just realized you said empty catching exceptions, not catching empty exceptions. Either way, unless you're dealing with IO, you probably want to avoid doing that for performance's sake.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With