473,412 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

How would you approach this using Structured Exception Handling?

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! =)
Jul 21 '05 #1
1 1111

"lover" <microsoft rulez!> wrote in message
news:uW**************@TK2MSFTNGP09.phx.gbl...
in the vb.old days we used to be able to do something like

First, trying to do a
Dim var1 as SomeClass = CType(SomeClass,nothing)
'Sorry, not VB man

Is perfectly legal and result in var1 = nothing, so you wouldn't get an
exception.
Second, just expend the try block:

try

_someIntegerVariable = _someVariableThatMightBeNothingOrNull
_anotherIntegerVariable = _anotherVariableThatMightBeNothingOrNull
yetAnotherIntegerVariable = _yetAnotherVariableThatMightBeNothingOrNull
catch ex as System.InvalidCastException
'don't care, handle silently
end catch

Will work just as well.
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: A. Saksena | last post by:
Hi, Do anybody have an idea of the performance penalty while using exception handling (specially with g++) Abhishek
3
by: HairlipDog58 | last post by:
I have a VC++6 project where I need to delay load a DLL. I used a structured exception handling frame and all seems to work when I build the debug version and run it (either in or out of the...
1
by: lover | last post by:
in the vb.old days we used to be able to do something like \\\ sub on local error goto typeMismatchHandler _someIntegerVariable = _someVariableThatMightBeNothingOrNull _anotherIntegerVariable...
18
by: Digital Puer | last post by:
Hi, I'm coming over from Java to C++, so please bear with me. In C++, is there a way for me to use exceptions to catch segmentation faults (e.g. when I access a location off the end of an array)?...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
3
by: Bruce One | last post by:
I am developing a new project in which we should have a good Exception Handling. Ive seen there is a Exception Handling App Block in Enterprise Library, also I could use the Try-Catch structure...
23
by: marora | last post by:
I keep hearing about not to use 'go_to' in your code. However, I don't know what's the reasoning behind it? Can any one here shed some light? Thanks in advance, Manish
14
by: Rex | last post by:
Re: Looking for Tips/Writeup on overall approach to Exception Processing Hi All - I am fairly new to C# and am wondering how to best implement (overall) Exception Processing within my...
5
by: George2 | last post by:
Hello everyone, I am learning set_se_translator, and there are some good resources about how to translate structured exception into C++ exception, like, ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.