L
lover
in the vb.old days we used to be able to do something like
\\\
sub
on local error goto typeMismatchHandler
_someIntegerVariable = _someVariableThatMightBeNothingOrNull
_anotherIntegerVariable = _anotherVariableThatMightBeNothingOrNull
_yetAnotherIntegerVariable =
_yetAnotherVariableThatMightBeNothingOrNull
exit sub
typeMismatchHandler:
if err = TypeMismatch then
'if it tries to set it to nothing, i don't care - handle silently
resume next
else
'handle real errors
end if
exit sub
end sub
///
off the top of my head, the first analogous approach i come up with using
SEH is:
\\\
sub
try
_someIntegerVariable = _someVariableThatMightBeNothingOrNull
catch ex as System.InvalidCastException
'don't care, handle silently
end catch
try
_anotherIntegerVariable = _anotherVariableThatMightBeNothingOrNull
catch ex as System.InvalidCastException
'don't care, handle silently
end catch
try
_yetAnotherIntegerVariable =
_yetAnotherVariableThatMightBeNothingOrNull
catch ex as System.InvalidCastException
'don't care, handle silently
end catch
end sub
///
....which in this trivial example is not that bad, but in my real program,
there are many more lines than just 3. i am trying to figure out a more
'elegant' approach to try to keep the code readable. (otherwise this sub
will be a mile long!)
....second thought off the top of my head would be to stick variables and
values in a arrays and loop through them - keeping the try-catch block in a
loop would keep things much more readable, and i'm going to fool around with
that as soon as i post this msg, but...
i guess what i'm really looking for here is try-catch's functional
equivalent of 'Resume Next'...
anyone have any ideas? approaches?
as always, any insight would be much appreciated!
TIA! =)
\\\
sub
on local error goto typeMismatchHandler
_someIntegerVariable = _someVariableThatMightBeNothingOrNull
_anotherIntegerVariable = _anotherVariableThatMightBeNothingOrNull
_yetAnotherIntegerVariable =
_yetAnotherVariableThatMightBeNothingOrNull
exit sub
typeMismatchHandler:
if err = TypeMismatch then
'if it tries to set it to nothing, i don't care - handle silently
resume next
else
'handle real errors
end if
exit sub
end sub
///
off the top of my head, the first analogous approach i come up with using
SEH is:
\\\
sub
try
_someIntegerVariable = _someVariableThatMightBeNothingOrNull
catch ex as System.InvalidCastException
'don't care, handle silently
end catch
try
_anotherIntegerVariable = _anotherVariableThatMightBeNothingOrNull
catch ex as System.InvalidCastException
'don't care, handle silently
end catch
try
_yetAnotherIntegerVariable =
_yetAnotherVariableThatMightBeNothingOrNull
catch ex as System.InvalidCastException
'don't care, handle silently
end catch
end sub
///
....which in this trivial example is not that bad, but in my real program,
there are many more lines than just 3. i am trying to figure out a more
'elegant' approach to try to keep the code readable. (otherwise this sub
will be a mile long!)
....second thought off the top of my head would be to stick variables and
values in a arrays and loop through them - keeping the try-catch block in a
loop would keep things much more readable, and i'm going to fool around with
that as soon as i post this msg, but...
i guess what i'm really looking for here is try-catch's functional
equivalent of 'Resume Next'...
anyone have any ideas? approaches?
as always, any insight would be much appreciated!
TIA! =)