The second one is correct and is the widely-accepted practice.

Syntax and semantics aside, even in Java we were taught to catch
*specific* exceptions first and the general exception (or the "catch-
all" exception block) last.




Regards,


Benj




On Nov 12, 12:50 am, OliE <olie....@gmail.com> wrote:
> Hi all,
>
> my co-worker and I had an argument about try catchs, so I thought
> about asking everyone here since I can't find an answer over my
> internets :P
>
> I found something I find weird in one of his try catch in his code.
> Instead of having multiple catch of different error types, he made
> this :
>
>         Catch ex As Exception
>             If ex.Message = "IOException" Then
>                 MsgBox("Communication Error")
>             Else
>                 MsgBox(ex.Message) 'ex.Message
>             End If
>
> I told him no to do so and use multiple catchs like this :
>
>         Catch exIO As IO.IOException
>             MsgBox("Communication Error")
>
>         Catch ex As Exception
>             MsgBox(ex.Message)
>
> But he is sure his method is faster / resource friendly than mine,
> while I think comparing strings takes longer than catching directly
> the exception.
>
> So, who's right ?
>
> Thanks for future anwsers and please excuse my english, my main
> language is french :)

Reply via email to