473,960 Members | 35,780 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

resume next in VB.NET ?

In VB 6 I can do the following:

Sub MySub
on error goto Err1
: --all my codes are here
: --say this is where the error occurs
: --this is where resume next will bring me after Err1
exit sub

Err1:
msgbox "error = " & error
resume next
end sub

With the above codes, when I get an error, it did not exit out of my
subroutine, instead I will go to the next statement after I get the error.
Can I do the same thing in VB.NET 2005 ? Thank you.

Currently in VB.NET, this is what I do:

Sub MySub
try
: --all my codes are here
Catch ex As Exception
Try
swError = New StreamWriter(Ap plication.Start upPath &
"\Log.txt", True)
swError.WriteLi ne(Now & " error = " & ex.Message)
swError.Close()
swError = Nothing
Catch ex2 As Exception
End Try
End Try
End Sub

With the above code, if I get an error, it will exit the sub and will not
execute the rest of the code in my subroutine.
Jun 27 '08
11 2041
Fniles,

I think that you have learned yourself a very bad way of creating code.

It would in my idea be nicer when you did it like this.

\\\
Sub
All your code that cannot throw an exception here
Try
swError = new StreamWriter(.. ...
Try
swError.Write line
Catch
'here you handle the writting errors
End Try
Catch
'here you handle the opening errors
Finally
'here you do the code as closing
'where setting something to nothing is as well a bad habit.
End Try
End Sub
///

If you have in one of these routines errors, then there is nothing to
resume.

Cor

Jun 27 '08 #11
fniles wrote:
>try
statment #1
catch 'note: no "ex as exception" necessary
end try
Does it mean that I want to do the above codes for each line of the codes ?
No. Not in that form, anyway.

This is the equivalent of "On Error Resume Next" with /no/ error
handling of any kind, something like this ...

On Error Resume Next
Statement1
Statement2
Statement3
' and so on

.... only worse. The Exception - whatever it might have been - only
exists for the duration of the Catch block (unless you Throw it again)
so, by the time you hit "End Try", it's /evaporated/ as if it never
happened:

Try
Statement1
Catch
End Try
' Even if Statement1 went wrong, we /don't/ know about it!!

Try
Statement2
Catch
End Try
' Even if Statement2 went wrong, we /don't/ know about it!!

So the above could work, so long as you put /something/ in the Catch
blocks.
Having said all that, might it not be better to push the Try..Catch
constructs into the routines that you're /calling/ instead?

Sub X()
Statement1()
Statement2()
End Sub

Sub Statement1()
Try
' whatever
Catch ex as Exception
End Try
End Sub

(and the same for Statement2())

Any Exception gets caught in the [called] routine and your main routine
never gets to see it (because it's been "handled" already).

HTH,
Phill W.
Jun 27 '08 #12

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

Similar topics

7
5219
by: jason | last post by:
Is there a way to avoid On Error Resume Next for: cnn.Open strCon SQL = "EXEC Customer @txtEmail='" & email_address & "'" set rs = cnn.execute(SQL) 'On error resume next rs("email_address") '// This record does not exist thus throwing up an error. I could use On
2
6826
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 you are debugging within IDE...? Here is an example from VB: Private SomeFunction () On Error GoTo ErrHandler: MyMethod this, that
3
4951
by: Dave | last post by:
Hi, I have a C# program that is parsing an XML file and loading a database table. Some of the elements may be missing but I want to continue with loading the data anyway because they may not be applicable. So, if '190' doesn't exist using the following code: doc.SelectSingleNode("descendant::companyinfo
5
8619
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 the On Error Resume next Statement, to avoid skipping the process of Inserting the records. But the Problem is
3
27470
by: bob.needler | last post by:
I know On Error Resume Next is generally considered lazy. But can someone tell me why the resume next in Exit_Handler does not seem to work? It generates the typical unhandled runtime error message from Access. If I comment out the 1st On Error Resume Next and the x = 1 / 0 on the next line there is no difference, i.e. ther same unhandled error on the same line. I included these 2 lines of code to demonstrate that On Error Resume Next...
7
21993
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
3800
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 doesn't move to next element... this sad thing but, it's indication that we must move to try catch instead of on error.
7
6505
by: Rob R. Ainscough | last post by:
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.
11
48037
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,
0
11355
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10839
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10037
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8407
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5096
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.