Force RTE for testing
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Force RTE for testing
Hi All,
Is there a way to force a run time error so that I can test different ways of error handling?
Thanks,
Mark
Is there a way to force a run time error so that I can test different ways of error handling?
Thanks,
Mark
Thanks,
Mark
Mark
-
- Administrator
- Posts: 78235
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Force RTE for testing
Yes:
Err.Raise 1234
if you want to simulate the error with error number 1234.
Err.Raise 1234
if you want to simulate the error with error number 1234.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Re: Force RTE for testing
Hi Hans,
I entered that into a button on-click routine and I always get application-defined or object-defined error box. Is that what I should expect or am I doing something wrong?
Thanks,
Mark
I entered that into a button on-click routine and I always get application-defined or object-defined error box. Is that what I should expect or am I doing something wrong?
Thanks,
Mark
Code: Select all
Private Sub Command34_Click()
On Error GoTo ErrHandler
Dim frmCurrentForm As Form, frmName As String
Set frmCurrentForm = Screen.ActiveForm
frmName = frmCurrentForm.Name
'MsgBox frmName
Err.Raise 1004
MyPrintScreen "o:\Projects\db_admin\errors\" & frmName & "_" & Format(Now(), "ddmmmyyyy_hhmm") & ".bmp"
Exit Sub
ErrHandler:
RecordError
MsgBox Err.Number & "-" & Err.Description
Exit Sub
End Sub
Thanks,
Mark
Mark
-
- Administrator
- Posts: 78235
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Force RTE for testing
The error message associated with error number 1004 is "Application-defined or object-defined error", so yes, that's the expected result.
Which error would you like to simulate?
Which error would you like to simulate?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Re: Force RTE for testing
Hi Hans,
I guess that I would like to get various errors based on the number. I will try some different ones.
Thanks,
Mark
I guess that I would like to get various errors based on the number. I will try some different ones.
Thanks,
Mark
Thanks,
Mark
Mark
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Re: Force RTE for testing
Hi Hans,
I pulled up a list of codes and entered 3040. Which if I am correct should be a disk I/O error. I get this.
I pulled up a list of codes and entered 3040. Which if I am correct should be a disk I/O error. I get this.
You do not have the required permissions to view the files attached to this post.
Thanks,
Mark
Mark
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Re: Force RTE for testing
On another note, does a msgbox being up on screen qualify as the active window? I am trying to do a screen capture of the error when it pops up and save that BMP to disk.
Thanks,
Mark
Thanks,
Mark
Thanks,
Mark
Mark
-
- Administrator
- Posts: 78235
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Force RTE for testing
Apparently Err.Raise only "knows" generic VBA errors. Try this version:santosm wrote:Hi Hans,
I pulled up a list of codes and entered 3040. Which if I am correct should be a disk I/O error. I get this.
Err.Raise Number:=3040, Description:=AccessError(3040)
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 78235
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Force RTE for testing
Yes, it does when I test it.santosm wrote:On another note, does a msgbox being up on screen qualify as the active window?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Re: Force RTE for testing
Thanks, the method you listed does pull the correct error number and description now. For the screen capture thing I am trying to do, it doesn't ways grab the msgbox window, it grabs the whole screen. Not sure why.
Screen Capture code attached as text file.
Code: Select all
Private Sub Command34_Click()
On Error GoTo ErrHandler
Dim frmCurrentForm As Form, frmName As String
Set frmCurrentForm = Screen.ActiveForm
frmName = frmCurrentForm.Name
'MsgBox frmName
Err.Raise Number:=3040, Description:=AccessError(3040)
Exit Sub
ErrHandler:
MsgBox Err.Number & "-" & Err.Description
RecordError 'this code does the screen capture
Exit Sub
End Sub
You do not have the required permissions to view the files attached to this post.
Thanks,
Mark
Mark
-
- Administrator
- Posts: 78235
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Force RTE for testing
The line
MyPrintScreen sPath
will only run when the user has closed the MsgBox - all code execution is temporarily suspended while the message box is displayed. I don't think there is a way around that.
MyPrintScreen sPath
will only run when the user has closed the MsgBox - all code execution is temporarily suspended while the message box is displayed. I don't think there is a way around that.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 495
- Joined: 13 Sep 2013, 07:56
Re: Force RTE for testing
Yes, it is modular too which means you have to close it before you can continue.santosm wrote:On another note, does a msgbox being up on screen qualify as the active window? I am trying to do a screen capture of the error when it pops up and save that BMP to disk.
Thanks,
Mark
Way round it? Write your own message box.
Regards, Ben
"Science is the belief in the ignorance of the experts."
- Richard Feynman
"Science is the belief in the ignorance of the experts."
- Richard Feynman
-
- 4StarLounger
- Posts: 495
- Joined: 13 Sep 2013, 07:56
Re: Force RTE for testing
You can use your own number. See the Help File. Here is an extract and an Example.HansV wrote:Apparently Err.Raise only "knows" generic VBA errors. Try this version:santosm wrote:Hi Hans,
I pulled up a list of codes and entered 3040. Which if I am correct should be a disk I/O error. I get this.
Err.Raise Number:=3040, Description:=AccessError(3040)
To see the help article, type in "err.raise" on a line, put the focus on the line and press the F1 keyRequired. Long integer that identifies the nature of the error. Visual Basic errors (both Visual Basic-defined and user-defined errors) are in the range 0–65535. The range 0–512 is reserved for system errors; the range 513–65535 is available for user-defined errors. When setting the Number property to your own error code in a class module, you add your error code number to the vbObjectError constant. For example, to generate the error number 513, assign vbObjectError + 513 to the Number property.
Const MyContextID = 1010407 ' Define a constant for contextID.
Function TestName(CurrentName, NewName)
If Instr(NewName, "bob") Then ' Test the validity of NewName.
' Raise the exception
Err.Raise vbObjectError + 513, "MyProj.MyObject", _
"No ""bob"" allowed in your name", "c:\MyProj\MyHelp.Hlp", _
MyContextID
End If
End Function
Regards, Ben
"Science is the belief in the ignorance of the experts."
- Richard Feynman
"Science is the belief in the ignorance of the experts."
- Richard Feynman
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Re: Force RTE for testing
Thanks Guys,
I did finally figure out that I was clicking OK before the screen capture was happening. So, this method of storing a picture of the fault won't work but I will still stamp the error info into a table and that will work fine for now. Thanks for all the pointers!
Mark
I did finally figure out that I was clicking OK before the screen capture was happening. So, this method of storing a picture of the fault won't work but I will still stamp the error info into a table and that will work fine for now. Thanks for all the pointers!
Mark
Thanks,
Mark
Mark