Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Default Error

Status
Not open for further replies.

guitardave78

Programmer
Sep 5, 2001
1,294
0
0
GB
Is it possible in a class to catch all error and change the way they are displayed.

This is more lazyness. I dont want to catch every possible error in every function of the class.

For example, if a path is not found you get this
Microsoft VBScript runtime error '800a004c'

Path not found

/explorer/includes/browserclass.asp, line 564

i would like it to just display

Path not found.

Or is there a way of catching the point that a class has been fully loaded (like initialize?)


}...the bane of my life!
 
Well, you could use the extensive error catching mechanism in VBScript (sarcasm intended):
Code:
On Error resume Next

[i]do some code[/i]
[i]do some code[/i]

If err.Number <> 0 Then 
   MyErrorFunction
   Exit Function
End If

[i]do some code[/i]
[i]do some code[/i]

If err.Number <> 0 Then 
   MyErrorFunction
   Exit Function
End If

[i]do some code[/i]
[i]do some code[/i]

If err.Number <> 0 Then 
   MyErrorFunction
   Exit Function
End If

On Error Goto 0

Function MyErrorFunction
   Response.Write "Sorry, an internal error occurred: " & err.Message
   'or you could do a case statement off the err.Number
End Function

And for the initialize you could set a class variables when it is loaded:
Code:
Class MyClass
   Public classLoaded

   Public Sub MyClass_Initialize()
      classLoaded = False
      [i]do some code[/i]
      [i]do some code[/i]
      [i]do some code[/i]

      classLoaded = True
   End Sub
End Class

:)

signature.png
 
ah, I can use class_terminate to do it all :p
Just set resume next at the top of the class, then have my if error<>0 etc in the terminate bit.

}...the bane of my life!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top