Proper exception handling is a topic in its own, but in your case
I would strongly suggest that you handle the possibility of a
InvalidCastException as follows.
Try
txtDate.Text = ("hi" / 0)
....
Catch ex As InvalidCastException
'Code to handle the specific exception
Response.write("You have entered an invalid date.")
Catch ex1 As Exception
'Code to handle all other exceptions
Response.write("There was an error.")
End Try
The "Try ...Catch" construct is designed to give the possibility of handling
each type of exception uniquely. The catch-construct will do the necessary
type checking for us, such that we should never have to write code like
> Catch ex As Exception
> if ex.GetType.ToString ="System.InvalidCastException" then
>
It sounds that what you try to do is actually input validation. Best
practise tend to discourage the use of exceptions for this purpose. Chances
are you should consider employing a validation scheme (such as .NET built-in
validators).
Proper exception handling in .NET is a new school of thought compared to
error handling in Access/VB.
You may benefit from further reading on the subject, such as
http://msdn.microsoft.com/library/de...us/dnbda/html/
emab-rm.asp
Tor Bådshaug
tor.badshaug [//at\\] bekk.no.