473,320 Members | 2,006 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,320 software developers and data experts.

Try...Catch... Resume??

In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything similiar
when using Try...Catch -- so how can one resume the next statement when an
error can be ignored?

Thanks, Rob.
Aug 23 '06 #1
7 6469
Rob,

Because that in this newsgroup not everybody knows about VB6 can you show
that Try Catch statement completely as you use it in VB6.

Thanks,

Cor

"Rob R. Ainscough" <ro*****@pacbell.netschreef in bericht
news:eb**************@TK2MSFTNGP05.phx.gbl...
In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything
similiar when using Try...Catch -- so how can one resume the next
statement when an error can be ignored?

Thanks, Rob.


Aug 23 '06 #2
On error resume next is still there (AFAIK actually it uses try/catch behind
the scene) or just catch only the block of statement you need (a single
statement if you really need).

You could also describe the exact problem (for example in some cases, you
can test if the argument would result in an exception rather than to catch
an exception that would be caused by the incorrect argument).
--
Patrice

"Rob R. Ainscough" <ro*****@pacbell.neta écrit dans le message de news:
eb**************@TK2MSFTNGP05.phx.gbl...
In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything
similiar when using Try...Catch -- so how can one resume the next
statement when an error can be ignored?

Thanks, Rob.


Aug 23 '06 #3
one way to do so is put many try...catch structures in your method, and
putting your stuff into blocks... when having a line that could cause an
error that can be ignored, place this line (and only this one) in the try
part of the try...catch, then continue...

Maybe there is another solution, but this one works...

ThunderMusic

"Rob R. Ainscough" <ro*****@pacbell.netwrote in message
news:eb**************@TK2MSFTNGP05.phx.gbl...
In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything
similiar when using Try...Catch -- so how can one resume the next
statement when an error can be ignored?

Thanks, Rob.


Aug 23 '06 #4

Rob,

I think that if you change the scope of the try...catch you will find that
you can accomplish what you are looking for. Take the following pseudo code
for example...

Try
For x = 1 to 100
' Do something that causes an error occasionally.
Next
Catch Exception
Using the preceding exception handling you cannot return to the loop to
continue. But if you simply change it to:

For x = 1 to 100
Try
' Do something that causes an error occasionally.
Catch Exception
Next

You're code can continue to work on the loop. When you catch exceptions you
want to keep it to the smallest scope possible and want to catch the most
specific exception possible. By this I mean, assume that you are using
File.Copy to copy a file. Looking in the MSDN documentation you can see that
it can throw 8 different exception types. You may be tempted to catch
System.Exception just to have one catch block but with a little forethought
you do not need to worry about all 8 of them. You can check the arguments
that you pass in before to make sure that they are valid and eliminate the
possibility of it throwing ArgumentException, ArgumentNullException,
DirectoryNotFoundException, FileNotFoundException, and NotSupportedOption.
If you have checked for permissions or used code access security to specify
your permissions you can avoid the UnuathorizedAccessException. Thus, you
would just need to catch the IOException which you can not really plan around
since you cannot know ahead of time if your hard drive is going to crash.

I hope this long winded answer is close to what you were looking for.

Michael
"Rob R. Ainscough" wrote:
In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything similiar
when using Try...Catch -- so how can one resume the next statement when an
error can be ignored?

Thanks, Rob.
Aug 23 '06 #5
I was hoping to avoid using many Try ... Catch constructs repeatedly. What
I'm trying to accomplish is basically ignore an element error when reading
thru an XML file -- if the element isn't in the file just continue reading
and ignore -- this allows me to work with XML structures that change where
I'm only interested in certain parts of the XML file.

MSDN states that I can't use a Resume statement in a Try...Catch -- either
use one approach or the other. I like the Try..Catch construct, but I was
hoping that I wouldn't loose my Resume functionality. .NET still supports
the On Error ... Resume so I guess I'll have to use that for this instances.

thanks, Rob.
"Michael" <Mi*****@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.com...
>
Rob,

I think that if you change the scope of the try...catch you will find that
you can accomplish what you are looking for. Take the following pseudo
code
for example...

Try
For x = 1 to 100
' Do something that causes an error occasionally.
Next
Catch Exception
Using the preceding exception handling you cannot return to the loop to
continue. But if you simply change it to:

For x = 1 to 100
Try
' Do something that causes an error occasionally.
Catch Exception
Next

You're code can continue to work on the loop. When you catch exceptions
you
want to keep it to the smallest scope possible and want to catch the most
specific exception possible. By this I mean, assume that you are using
File.Copy to copy a file. Looking in the MSDN documentation you can see
that
it can throw 8 different exception types. You may be tempted to catch
System.Exception just to have one catch block but with a little
forethought
you do not need to worry about all 8 of them. You can check the arguments
that you pass in before to make sure that they are valid and eliminate the
possibility of it throwing ArgumentException, ArgumentNullException,
DirectoryNotFoundException, FileNotFoundException, and NotSupportedOption.
If you have checked for permissions or used code access security to
specify
your permissions you can avoid the UnuathorizedAccessException. Thus, you
would just need to catch the IOException which you can not really plan
around
since you cannot know ahead of time if your hard drive is going to crash.

I hope this long winded answer is close to what you were looking for.

Michael
"Rob R. Ainscough" wrote:
>In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything
similiar
when using Try...Catch -- so how can one resume the next statement when
an
error can be ignored?

Thanks, Rob.

Aug 23 '06 #6
I do this all the time, just make your readElement call a function with a try
catch block in that function, if element is not there just return empty
string. Pass in xPath and elementName, return a string.
--
Just another lost developer.....
"Rob R. Ainscough" wrote:
I was hoping to avoid using many Try ... Catch constructs repeatedly. What
I'm trying to accomplish is basically ignore an element error when reading
thru an XML file -- if the element isn't in the file just continue reading
and ignore -- this allows me to work with XML structures that change where
I'm only interested in certain parts of the XML file.

MSDN states that I can't use a Resume statement in a Try...Catch -- either
use one approach or the other. I like the Try..Catch construct, but I was
hoping that I wouldn't loose my Resume functionality. .NET still supports
the On Error ... Resume so I guess I'll have to use that for this instances.

thanks, Rob.
"Michael" <Mi*****@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.com...

Rob,

I think that if you change the scope of the try...catch you will find that
you can accomplish what you are looking for. Take the following pseudo
code
for example...

Try
For x = 1 to 100
' Do something that causes an error occasionally.
Next
Catch Exception
Using the preceding exception handling you cannot return to the loop to
continue. But if you simply change it to:

For x = 1 to 100
Try
' Do something that causes an error occasionally.
Catch Exception
Next

You're code can continue to work on the loop. When you catch exceptions
you
want to keep it to the smallest scope possible and want to catch the most
specific exception possible. By this I mean, assume that you are using
File.Copy to copy a file. Looking in the MSDN documentation you can see
that
it can throw 8 different exception types. You may be tempted to catch
System.Exception just to have one catch block but with a little
forethought
you do not need to worry about all 8 of them. You can check the arguments
that you pass in before to make sure that they are valid and eliminate the
possibility of it throwing ArgumentException, ArgumentNullException,
DirectoryNotFoundException, FileNotFoundException, and NotSupportedOption.
If you have checked for permissions or used code access security to
specify
your permissions you can avoid the UnuathorizedAccessException. Thus, you
would just need to catch the IOException which you can not really plan
around
since you cannot know ahead of time if your hard drive is going to crash.

I hope this long winded answer is close to what you were looking for.

Michael
"Rob R. Ainscough" wrote:
In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything
similiar
when using Try...Catch -- so how can one resume the next statement when
an
error can be ignored?

Thanks, Rob.


Aug 24 '06 #7
What is the method you are using to read the XML file ? IMO having a missing
optional element shouldn't raise an exception as this is not an unexpected
situation.

--
Patrice

"Rob R. Ainscough" <ro*****@pacbell.neta écrit dans le message de news:
OA**************@TK2MSFTNGP02.phx.gbl...
>I was hoping to avoid using many Try ... Catch constructs repeatedly. What
I'm trying to accomplish is basically ignore an element error when reading
thru an XML file -- if the element isn't in the file just continue reading
and ignore -- this allows me to work with XML structures that change where
I'm only interested in certain parts of the XML file.

MSDN states that I can't use a Resume statement in a Try...Catch -- either
use one approach or the other. I like the Try..Catch construct, but I was
hoping that I wouldn't loose my Resume functionality. .NET still supports
the On Error ... Resume so I guess I'll have to use that for this
instances.

thanks, Rob.
"Michael" <Mi*****@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.com...
>>
Rob,

I think that if you change the scope of the try...catch you will find
that
you can accomplish what you are looking for. Take the following pseudo
code
for example...

Try
For x = 1 to 100
' Do something that causes an error occasionally.
Next
Catch Exception
Using the preceding exception handling you cannot return to the loop to
continue. But if you simply change it to:

For x = 1 to 100
Try
' Do something that causes an error occasionally.
Catch Exception
Next

You're code can continue to work on the loop. When you catch exceptions
you
want to keep it to the smallest scope possible and want to catch the most
specific exception possible. By this I mean, assume that you are using
File.Copy to copy a file. Looking in the MSDN documentation you can see
that
it can throw 8 different exception types. You may be tempted to catch
System.Exception just to have one catch block but with a little
forethought
you do not need to worry about all 8 of them. You can check the
arguments
that you pass in before to make sure that they are valid and eliminate
the
possibility of it throwing ArgumentException, ArgumentNullException,
DirectoryNotFoundException, FileNotFoundException, and
NotSupportedOption.
If you have checked for permissions or used code access security to
specify
your permissions you can avoid the UnuathorizedAccessException. Thus,
you
would just need to catch the IOException which you can not really plan
around
since you cannot know ahead of time if your hard drive is going to crash.

I hope this long winded answer is close to what you were looking for.

Michael
"Rob R. Ainscough" wrote:
>>In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything
similiar
when using Try...Catch -- so how can one resume the next statement when
an
error can be ignored?

Thanks, Rob.


Aug 24 '06 #8

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

Similar topics

2
by: Darta | last post by:
OK- I volunteer to be shot if this question is stupid... BUT, is there a way to, when you catch an exception in the catch{} handler, resume to the same line of code that generated an error while...
5
by: Rob R. Ainscough | last post by:
Coming from VB6 to VB.NET, it appears if I opt to use the Try Catch approach I don't have any way to RESUME from within my catch statement? What I often do is resolve the problem in my catch...
5
by: itsupport1 | last post by:
Hi, I am importing some records from one table to another table, and due to Constraints in the destination table, it Throws an Exception and Skip the Whole Rest of records. So I did implement...
15
by: Neo | last post by:
Hello All, Although, I have read all the advantages of using Try Catch Block instead of "On error goto", I am still confused what is alternative for classic "Resume" statement. "Resume" was one...
7
by: fniles | last post by:
In VB 6.0 in the error trapping, we can do "resume next" to continue on the next code. How can we do that in .NET with "Try", "Catch","End Try" ? Thanks
4
by: Neo | last post by:
I found on error resume next doesn't work in for each... e.g. on error resume next for each x in y 'do stuff next if you have an error in for each loop, it falls in infinite loop... it...
11
by: Maxwell2006 | last post by:
Hi, I know that this is not a good practice, but I wonder do we have "on error resume next" in C#? Thanks,
19
by: kimiraikkonen | last post by:
Hi, I want to find out if there's difference between "On Error Resume Next" error handler and leaving "catch" block empty in a try-catch-end try block to ignore exceptions which i don't approve of...
3
by: sriharikabattula | last post by:
hi, i am uploading .doc,.docX,rtf files during registration level and that path can be saved in database(i am using database MYSQL).when user want to see his resume he/she can login and retrive...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.