Normally I use Try/Catch for just one exception type and a narrow section of code. Looking at the future of Sockets they will use Try/Catch instead of checking True/False conditions. Is it better to have many Try/Catch loops in a method, or have most of the socket code in a larger scope with several catch types at the end? I assume one major reason for this change is code execution speed, not having to check for all the True/False conditions - assume all is well unless an exception is triggered.
That being said, here is some example code:
Dim mbTest As NEW MemoryBlock(10) Try mbTest.StringValue(9,5) = "Hello" Catch erData As NilObjectException MsgBox("Will not execute this, cause no Nil Object issues") Catch erData As RunTimeException MsgBox("Will execute this") Catch erData As OutOfBoundsException MsgBox("Yes, out of bounds; but won't execute this") End Try
In the code above, Catch RunTimeException and Catch OutOfBoundsException need to switch places if you want to actually catch the Out of Bounds triggered by trying to write "ello" beyond the size of mbTest.
Is RunTimeException the only catch ALL where something like this matters, or are their other catch types where the order is important?