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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP 2.0 How to catch and handle error code?

Status
Not open for further replies.

joggi

Programmer
Nov 8, 2006
44
YU
I wonder how to catch error in the ASP.NET?

1. I have web form and when I click Add button I call Function Insert from my Class1
2. When function Insert has an error how to pass that error to my web form and where to show this error?
3. How to catch error code and handle error, for instance in my VB/SQL server project code I have Case 2627 “Record must have unique value”. How to do this in ASP.NET 2.0?

I am new in ASP.NET so I am very confused with this.

Thanks in advance


 
try
{ <your code to do stuff> }
catch {Exception Ex)
{
<handle error like Ex.Message.ToString() to display error>
}
Finally
{
<code that HAS to execute>
}
 
I know this Try...catch...er.message...
But what am I looking for is Error.Number not Error.message

Like I have in my VB 6 project:

Err:
Select Case Err.Number

Case -2147467259, 17:
MsgBox "There is no connection"
Case 2627, 3621:
MsgBox "Field is unique."
Case Else
MsgBox (Err.Source & vbCrLf & Err.Description & vbCrLf & Err.Number)
End Select
 
Thanks, but what if I have division by zero. This is not sqlexception?
 
This is .NET not VB6. You wil lhave to account for all exception types in your case. You can have multiple catch statements per Try block
 
Thank you.
Now I have another problem. I have webform and on page load I call one function from Class1. When error ocurrs in class I want the class to pass that error to the form, like in VB6.

I don't know how to do this. In VB6 I have in Tool Options to set:
Break on all errors
Break in Class Module
Break on Unhandled errors

Is it possible in .NET?
 
Create a property on your page and set the value if an error occurs. then on the page you can check if that propety has a value and do what you want from there.
 
Thank you, I found this:

Try
.... code

Catch x As SqlException
Throw x
End Catch

So my class throw error to webform.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top