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. 11 2027
On 17 Apr, 14:55, "fniles" <fni...@pfmail. comwrote:
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.
You should put Try and Catch around all code you suspect may cause an
error. So
Try
: --one line of code that you need to catch errors on
Catch ex2 As Exception
End Try
Try
: --one line of code that you need to catch errors on
Catch exc as Exception
End Try
You can also put in a Finally clause that will run whether there is an
exception or not!
Good luck!
AFAIK you still have on error resume next in VB 2005...
That said I would avoid this. Either you know what is the error (this is the
purpose of try catch) and you can do something about this or this is an
unknown error and IMO still trying to blindly runs will make things worse...
--
Patrice
"fniles" <fn****@pfmail. coma écrit dans le message de news: eC************* *@TK2MSFTNGP05. phx.gbl...
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.
I agree with other responders about try-catch being a better construct. That
said, with breakpoints on the two commented statements below, the behavior
you want happens. The i\j error occurs, then a branch to err1, and finally
resume next back in sequence.
Sub MySub()
Dim i, j, k As Integer
On Error GoTo err1
k = i \ j
k = k ' break here second
Return
err1:
k = k ' break here first
Resume Next
End Sub
"fniles" wrote:
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.
"fniles" <fn****@pfmail. comschrieb
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.
It's probably very rare that one wants to ignore errors in multiple
consecutive lines. I think the only way to recreate the VB6 behavior is:
try
statment #1
catch 'note: no "ex as exception" necessary
end try
try
statment #2
catch
end try
And so on. However, I see, if you wanted to do the same error handling
in each catch block, you'd have to write the same each time.
Armin
fniles wrote:
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.
Correct. You have to wrap your Exception handling as "tightly" around
the [potential] source of the error as you can, even if that's around a
single call to a.n.other function.
Also:
If you need to support Vista (with UAC in place) any time soon, think
twice about logging into the application's "own" directory. "Regular"
Users won't have permission to write anything under "Program Files" so
your StreamWriter creation could well fail .
Setting swError to Nothing has no useful effect. Close() has already
called Dispose() on the StreamWriter and the underlying FileStream.
HTH,
Phill W.
I'm not trying to be mean, but .. you need a HEAVY DOSE of how to handle
exceptions in DotNet.
Read and bookmark this page: http://blogs.msdn.com/kcwalina/archi...16/396787.aspx
...
Throw out your VB6 mentality all together. Just because you ~can~ in
VB.NET, doesn't mean you should.
...
"fniles" <fn****@pfmail. comwrote in message
news:eC******** ******@TK2MSFTN GP05.phx.gbl...
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.
Hello Phill,
If you need to support Vista (with UAC in place) any time soon, think
twice about logging into the application's "own" directory. "Regular"
Users won't have permission to write anything under "Program Files" so
your StreamWriter creation could well fail .
This is not just with Windows Vista, but also With XP (and also with
2000/NT AFAIK). I really wonder, why this reduced right thingy is always
mentioned in combination with Vista... If you use a limited account with
XP (as you should) you also can't write into the "Program files" directory.
Therefore:
- if you need to share write access for files among users, write into
"C:\Documen ts and Settings\All Users\Applicati on Data"
- if you need to write files for each user separately, write into
"C:\Documen ts and Settings\<User name>\Applicati on Data"
Since MS can change the paths at their own discretion (as they did with
Vista - there it is C:\Users\...) it is always a good idea to get the
path from the .NET framework.
ApplicationData directory for the running program under the logged-in user:
My.Computer.Fil eSystem.Special Directories.Cur rentUserApplica tionData
(=C:\Documents and Settings\<User name>\Applicati on
Data\Company\Pr ogramName\Versi on)
ApplicationData directory for the logged-in user:
Environment.Get FolderPath(Envi ronment.Special Folder.Applicat ionData)
(=C:\Documents and Settings\<User name>\Applicati on Data)
ApplicationData directory for all users:
Environment.Get FolderPath(Envi ronment.Special Folder.CommonAp plicationData)
(=C:\Documents and Settings\All Users\Applicati on Data)
Best regards,
Martin
Thank you.
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 ?
"Armin Zingler" <az*******@free net.dewrote in message
news:uT******** ******@TK2MSFTN GP02.phx.gbl...
"fniles" <fn****@pfmail. comschrieb
>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.
It's probably very rare that one wants to ignore errors in multiple
consecutive lines. I think the only way to recreate the VB6 behavior is:
try
statment #1
catch 'note: no "ex as exception" necessary
end try
try
statment #2
catch
end try
And so on. However, I see, if you wanted to do the same error handling in
each catch block, you'd have to write the same each time.
Armin
On 2008-04-17, Martin H. <hk***@gmx.netw rote:
Hello Phill,
>If you need to support Vista (with UAC in place) any time soon, think twice about logging into the application's "own" directory. "Regular" Users won't have permission to write anything under "Program Files" so your StreamWriter creation could well fail .
This is not just with Windows Vista, but also With XP (and also with
2000/NT AFAIK). I really wonder, why this reduced right thingy is always
mentioned in combination with Vista... If you use a limited account with
XP (as you should) you also can't write into the "Program files" directory.
I think because the restrictions are tighter under Vista. It fails even
as an admin account - which wasn't the case on XP.
In other words, you have to do the right thing always....
--
Tom Shelton This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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
|
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
|
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
|
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...
| |
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
|
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.
|
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.
|
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,
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |