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

Returning from a catch statement

Hi All

In VB6 I used to catch exceptions in a goto errtrap call then resume if I
could handle the problem and continue within the routine or function

I am not sure how to do this in VB 2005 from within a catch statement

Any ideas appreciated
--
Regards
Steve
Dec 1 '05 #1
4 1346
You can´t do that in VB.NET, at least not directly, you have to use nested
Try/Catch blocks

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Steve" <St***@discussions.microsoft.com> escribió en el mensaje
news:7A**********************************@microsof t.com...
Hi All

In VB6 I used to catch exceptions in a goto errtrap call then resume if I
could handle the problem and continue within the routine or function

I am not sure how to do this in VB 2005 from within a catch statement

Any ideas appreciated
--
Regards
Steve

Dec 1 '05 #2
"Steve" <St***@discussions.microsoft.com> schrieb:
In VB6 I used to catch exceptions in a goto errtrap call then resume if I
could handle the problem and continue within the routine or function

I am not sure how to do this in VB 2005 from within a catch statement


You cannot exactly do the same without putting each statement into its
separate 'Try...Catch' block. Note that 'On Error GoTo...' is still
available in VB.NET.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 1 '05 #3
Steve,
As Carlos suggests, you cannot do that.

The "best" you could do is to put a Try/Catch around each of the commands
you want retry and have the Catch block retry the Try Block. I find using
Goto in the Catch block the "easiest" way to "Retry", others have put the
entire Try/Catch in a loop...

BTW: I've heard all the arguments about how Goto is evil & should be
avoided, in this case the "Goto Retry" is more like a "Retry" statement. Yes
"goto retry" could be used for evil, however it can also be used for good...

Something like:
Try Retry:
'...something

Catch ex as FileNotFoundException

If MessageBox.Show("File does not exit!", _
Application.ProductName, _
MessageBoxButtons.RetryCancel, _
MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2) _
= DialogResult.Retry Then
GoTo retry
End If

End Try


Caution: With either the Goto Retry or a loop, be certain to allow your
users an Out, so you don't get into an endless loop.

Hope this helps
Jay
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Steve" <St***@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...
| Hi All
|
| In VB6 I used to catch exceptions in a goto errtrap call then resume if I
| could handle the problem and continue within the routine or function
|
| I am not sure how to do this in VB 2005 from within a catch statement
|
| Any ideas appreciated
|
|
| --
| Regards
| Steve
Dec 1 '05 #4
Hi Carlos, Jay, Herfried

Thank you all for your replies
Regards
Steve
"Steve" <St***@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...
Hi All

In VB6 I used to catch exceptions in a goto errtrap call then resume if I
could handle the problem and continue within the routine or function

I am not sure how to do this in VB 2005 from within a catch statement

Any ideas appreciated
--
Regards
Steve

Dec 2 '05 #5

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

Similar topics

23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
5
by: Greg Wilkerson | last post by:
Ok, Someone tell me what I'm doing wrong. The statement below is returning 527.0 in v, instead of the expected 215. Am I missing something? double v; if (Double.TryParse("0d7",...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
2
by: Jeroen | last post by:
Here's the situation. My program will be able to start with an argument (a path to a file) and then run a batch of commands in that file. So if an argument is provided to the main method, the...
0
by: Maart_newbie | last post by:
Hi all, I've got a question about returning the value of a pk-column to a DataTable after inserting a row (via a data-adapter) using MySql5. Here is the SQL and code concerned: ...
4
by: =?Utf-8?B?Sm9obiBTaW1wc29u?= | last post by:
Like every developer, I've got tons of error trapping code that hard code the name of the function or sub name so I can error log it. It seems from other discussions that the only way to get the...
11
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have the method below that returns a bool, true or false depending on if the conversion to date tiem works. It takes a string input. I am only returning the bool but would also like to...
4
by: rbjorkquist | last post by:
This is my first attempt at writing/using web services, so any and all comments will be greatly appreciated. With that said, I am also by no means saying this is the correct either. I have...
8
by: =?Utf-8?B?U2F2dm91bGlkaXMgSW9yZGFuaXM=?= | last post by:
Is it right when placing the RETURN statement inside the TRY or inside the CATCH statement, when there is a FINALLY clause? Especially when there is a transaction going on, in the try/catch block?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.