They make sense since the Op knows that there is socket related exception which Op wrote to it's own catch block. To me the the code was only getting SocketException for a while and then he got other excepion which it couldn't caught by SocketException and then he added the same catch code block with Exception without taking the account of future coders since he got relief at that moment.
User 11360346
Posts
-
Multiple Catch blocks that do the same thing... -
Multiple Catch blocks that do the same thing...No that is not the intension. Op misses to implement the appropriate logic behind once the error occurred in SocketException which he copied similar catch block in the Exception block.
-
Multiple Catch blocks that do the same thing...See my reply here. [^]
-
Multiple Catch blocks that do the same thing...Yes you do need to have the catch block. In fact you may need to add more based on what
Dosomething()
does. What op need to do is to implement the appropriate logic in the catch block which I already said it in my first response. -
Multiple Catch blocks that do the same thing...:)
-
Multiple Catch blocks that do the same thing...The fact that you still ignore the
Dosomething()
method do, you generalize that both catches block get the same exception. Even I gave you example that the method might throw DBException and you expect the SocketException get exception based on your assumption. -
Multiple Catch blocks that do the same thing...Are you saying the message will always be the same ? This is a trick, If you do get it. :)
-
Multiple Catch blocks that do the same thing...It does matter, a self ref [^] How do you know the code executed the same ? YOU DON'T KNOW WHAT THE METHOD(Dosomething()) DO. What we know both exception was not utilized as such.
-
Multiple Catch blocks that do the same thing...We all know that managed .Net exception are derived from Exception class. If you are asking why the rest of derived Exception such as socketexception, Dbexception are created then that is another question. And it won't be necessary to allow multiple catch statement block from the compiler. Off course if you leave/comment out the above socketexception then the error definitely go to exception block, b/c of the reason that I stated above. Onething sure to know here, you can't determine to refactor the code by looking that code only, even we don't know either a SocketException will occur or not. G. Day
-
Multiple Catch blocks that do the same thing...They don't occur exactly with the same reason. Off course both catches exception but how each one will occur determine by the actual method logic. Suppose Dosomething() has DB process, then where you will think possible to be catched if error happens. On catch (Exception ex) block and where do you think the socket error will be catched on (SocketException sex). That is why the method logic determine the exception occurence.
-
Multiple Catch blocks that do the same thing...We can't predict looking the above code since we don't know what
Dosomething()
method exactly do. What we can infer is that there is a socket processing behind since there is a catch exception on it. -
Multiple Catch blocks that do the same thing...Yes it has purpose. You should see this msdn article. [^] But it wasn't utilized as suppose to.
-
Why one .NET developer is leaving the ecosystem2 points. 1. Angel leaves .Net environment, who cares 2. Not everybody should be Android Dev.
-
The role of a senior developerThese days a bunch of grads got a title Technical Lead, Systems Lead ... with in 6th month or less. This is v annoying and ethically wrong IMHO.Don't mention how they got the job. NO INTERVIEW(it's who you know rather than what you know).
-
51% of Americans believe storms affect cloud computingI believe the conducted survey is based on bunch of morons. Favon.