473,499 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error trapping not working

On Winxp Pro
I try to trap an error:

On error resume next
If (Err.Number <> 0) Then
End sub
End If

but no matter what the case Err.Number = 0. When I was using visual basic
6.0 on a win2k pro computer, errors were returned with values other than 0.
Is there a patch I need to download or do I need to upgrade to VB.Net or
something?

Jul 17 '05 #1
10 6475

"aaron" <at******@yahoo.com> wrote in message
news:c4**********@nntp6.u.washington.edu...
On Winxp Pro
I try to trap an error:

On error resume next
If (Err.Number <> 0) Then
End sub
End If

but no matter what the case Err.Number = 0. When I was using visual basic
6.0 on a win2k pro computer, errors were returned with values other than 0. Is there a patch I need to download or do I need to upgrade to VB.Net or
something?

"resume next" means exactly that.. continue with the next statement so it
can't catch errors (basically you are ignoring errors). What you might want
to do to catch errors is probably:

Sub SomeSub()
On Error GoTo ErrorHan

'code which may generate error

Exit Sub

ErrorHan:
Select Case Err.Number ' Evaluate error number.
Case xx 'handle it
Case 'etc
End Select

Resume

End Sub
Jul 17 '05 #2
On Wed, 31 Mar 2004 02:55:39 GMT, "Raoul Watson"
<Wa*****@IntelligenCIA.com> wrote:
<snip>

"resume next" means exactly that.. continue with the next statement so it
can't catch errors (basically you are ignoring errors). What you might want
to do to catch errors is probably:

Sub SomeSub()
On Error GoTo ErrorHan

'code which may generate error

Exit Sub

ErrorHan:
Select Case Err.Number ' Evaluate error number.
Case xx 'handle it
Case 'etc
End Select

Resume


Raoul, I totally disagree, both with what you say about
On Error Resume Next
and your 'improved' alternative

I suggest that you check out On Error Resume Next very carefully
- you will find that
a) it works
b) use of it makes simpler code

To the OP - try this

Private Sub Command1_Click()
Dim I As Integer

On Error Resume Next
I = I / 0
If Err Then MsgBox Err.Description

End Sub

Jul 17 '05 #3
Thanks, with your hints I found that the problem is the error is not being
passed to my other function. How do I pass an error object or what is the
best way to pass an error if I want to pass both the description and the
number? I have:

Sub SomeSub()
On Error Resume Next

'code that generates error

If Err Then
MyError(Err) 'pass error object????
End If
End Sub
---------------------------
Sub MyError (MyErrorObject as ErrObject)

msgbox MyErrorObject.number 'it is always 0 because it's not being passed

End Sub

Thanks!

"J French" <er*****@nowhere.com> wrote in message
news:40****************@news.btclick.com...
On Wed, 31 Mar 2004 02:55:39 GMT, "Raoul Watson"
<Wa*****@IntelligenCIA.com> wrote:
<snip>

"resume next" means exactly that.. continue with the next statement so it
can't catch errors (basically you are ignoring errors). What you might wantto do to catch errors is probably:

Sub SomeSub()
On Error GoTo ErrorHan

'code which may generate error

Exit Sub

ErrorHan:
Select Case Err.Number ' Evaluate error number.
Case xx 'handle it
Case 'etc
End Select

Resume


Raoul, I totally disagree, both with what you say about
On Error Resume Next
and your 'improved' alternative

I suggest that you check out On Error Resume Next very carefully
- you will find that
a) it works
b) use of it makes simpler code

To the OP - try this

Private Sub Command1_Click()
Dim I As Integer

On Error Resume Next
I = I / 0
If Err Then MsgBox Err.Description

End Sub

Jul 17 '05 #4

"aaron" <at******@yahoo.com> wrote
Thanks, with your hints I found that the problem is the error is not being
passed to my other function. How do I pass an error object or what is the
best way to pass an error if I want to pass both the description and the
number? I have:

The Err Object is a global object. You should not pass it as a parameter.
The called sub will see the same error object that was present in the
caller routine. If you want to clear the error for use in your called sub,
then you will have to store the Err object values before you do anything
that would clear them out.

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #5

"J French" <er*****@nowhere.com> wrote in message
news:40****************@news.btclick.com...
On Wed, 31 Mar 2004 02:55:39 GMT, "Raoul Watson"
<Wa*****@IntelligenCIA.com> wrote:
<snip>
"resume next" means exactly that.. continue with the next statement so it
can't catch errors (basically you are ignoring errors). What you might wantto do to catch errors is probably:

Sub SomeSub()
On Error GoTo ErrorHan

'code which may generate error

Exit Sub

ErrorHan:
Select Case Err.Number ' Evaluate error number.
Case xx 'handle it
Case 'etc
End Select

Resume


Raoul, I totally disagree, both with what you say about
On Error Resume Next
and your 'improved' alternative


I am not sure you read my post carefully.

1. My method is not "improved" that's a standard method. Even the VB help
file will show you a similar code for "on error". I have been using that
method over 25 years.

2. I never said On error resume next doesn't work, I use it all the time,
but like I said it resumes with the next statement so in essence "ignoring"
the error. For example:

On error resume next
open "filedoesntexist" for input as #1
debug.print "we get here even if file doesn't exist".
I suggest that you check out On Error Resume Next very carefully
- you will find that
a) it works


See above.

Your method is fine too. I don't have a problem with you having the "last
word".
Jul 17 '05 #6
er*****@nowhere.com (J French) wrote in message news:<40****************@news.btclick.com>...
<cut>
Raoul, I totally disagree, both with what you say about
On Error Resume Next
and your 'improved' alternative

I suggest that you check out On Error Resume Next very carefully
- you will find that
a) it works
b) use of it makes simpler code


I actually agree that it can make for simpler code and use it myself
(probably more often than I should). When recommending it you should
probably also note that
c) it adds overhead to the app and slows execution
d) it can mask bugs if you don't check for errors after any line that
might generate them

it's fine for short sections of code but not always best for longer
routines.
Jul 17 '05 #7
On Wed, 31 Mar 2004 22:30:20 GMT, "Raoul Watson"
<Wa*****@IntelligenCIA.com> wrote:

<snip>

Your method is fine too. I don't have a problem with you having the "last
word".


I really don't care - as long as you make an informed choice
Jul 17 '05 #8
On 31 Mar 2004 16:01:32 -0800, bu*******@earthlink.net (Bob Butler)
wrote:

<snip>
I actually agree that it can make for simpler code and use it myself
(probably more often than I should). When recommending it you should
probably also note that
c) it adds overhead to the app and slows execution ... a tadd) it can mask bugs if you don't check for errors after any line that
might generate them Very true
it's fine for short sections of code but not always best for longer
routines.

That is a different subject - but I get your drift
Jul 17 '05 #9
It doesn't work.

If I do a debug.print Err.Number before I call the other function, it prints
out the error number correctly, but once I call the other function and try
to do a debug.print within that function I get a 0.
"Larry Serflaten" <Ab***@SpamBusters.com> wrote in message
news:40********@corp.newsgroups.com...

"aaron" <at******@yahoo.com> wrote
Thanks, with your hints I found that the problem is the error is not being passed to my other function. How do I pass an error object or what is the best way to pass an error if I want to pass both the description and the
number? I have:

The Err Object is a global object. You should not pass it as a parameter.
The called sub will see the same error object that was present in the
caller routine. If you want to clear the error for use in your called

sub, then you will have to store the Err object values before you do anything
that would clear them out.

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #10

"aaron" <at******@yahoo.com> wrote
It doesn't work.

If I do a debug.print Err.Number before I call the other function, it prints
out the error number correctly, but once I call the other function and try
to do a debug.print within that function I get a 0.


Show your work. Post a small demo that reproduces that behaviour.

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #11

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

Similar topics

9
10870
by: Robert Wing | last post by:
I support an MS Access application in which errors are trapped using the On Error statement. Just recently, the users of this system have experienced run-time error number 3021 on a random basis. ...
3
5438
by: tom blower | last post by:
Access 2k (10.6501.6714) SP3 For YEARS the code line "On Error Resume Next" has worked without any problems. It is an essential tool. A couple of days ago, I put in another hard drive, mentioned...
0
1176
by: tom blower | last post by:
The Options are set OK. What was wrong was that I had inadvertently set Error Trapping to 0. I had been playing with this the other day. Application.SetOption "Error Trapping", 2 on loading...
13
4430
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
2
2159
by: Bill Stock | last post by:
I have a subform which is causing a 3314 (Field can't contain a null value because required is set to True) error. I solved this problem by trapping it in the before update event. But then I...
2
1555
by: Fred Nelson | last post by:
I'm devloping a VB.NET web application and I'm having a problem with trapping errors and logging the cause of them. When an unexpected error occurs I want to write it to a file - or e-mail it to...
2
3857
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
9
2093
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
4
7582
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
3
4492
by: GazK | last post by:
I have been using an xml parsing script to parse a number of rss feeds and return relevant results to a database. The script has worked well for a couple of years, despite having very crude...
0
7132
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
7009
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
7223
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
7390
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...
1
4919
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...
0
4602
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...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
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 ...
0
302
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...

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.