The code:
public Constructor(string vConnection_String)
{
try
{
mConnection_String = vConnection_String;
}
catch (Exception ex)
{
ExceptionHandler.CatchEx(ex);
}
}
I think the person who programmed this was "just being careful," but out of interest what exceptions could be thrown on a line that does a string assignment like this one here? I can think of System.OutOfMemoryException, but what others?
Thank you
When data structures or data sets that reside in memory become so large that the common language runtime is unable to allocate enough contiguous memory for them, an OutOfMemoryException exception results.
To avoid this exception while working with StringBuilder, we can call the constructor StringBuilder. StringBuilder(Int32, Int32) and can set the MaxCapacity property to a value that will be large enough to serve the accommodation required when we expand the corresponding StringBuilder object.
Herb Sutter write several great articles about exception safety, and in one of them he shows 3 types of exception safety:
the basic guarantee
the strong guarantee
the nothrow guarantee
This principles are commonly known in C++ world but we could use them in .net world too because one of them takes place in your situation.
If mConnection_String is a field of type System.String (or another reference type) than you definitely know, that this code is "nothrow guarantee", because simple assignment for reference type could not throw exceptions at all.
Nothing can happen here in my point of view. If you use something like subversion then you will probably see that someone removed some code here without removing the exception handling. Otherwise it is just silly.
You can remove the verbose code without any doubts.
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