Could some body explain exception vs error in asp.net
They both the same thing. An exception happens in "exceptional circumstances" i.e. the application cannot carry on, which is an error.
I'm assuming you're talking about the On Error
statement in VB.NET which is just an "unstructured" way of handling Exceptions in VB.NET (it was carried over from the VB syntax to make things more familiar for VB developers).
Structured Error handling (using try/catch blocks) is the more accepted way of Exception handling in your code.
Take, for example, the following VB.NET Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
On Error GoTo nextstep
Dim result As Integer
Dim num As Integer
num = 100
result = num / 0
nextstep:
MsgBox("Control Here")
End Sub
End Class
Could be re-written using structured Exception handling quite easily:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim result As Integer
Dim num As Integer
Try
num = 100
result = num / 0
Catch ex As Exception
MsgBox("Control Here")
End Try
End Sub
End Class
Some people use error to refer to an unrecoverable discrepancy. Some use error to mean any possible issue.
I would say that an error is anytime a program deviates from the expected flow. So you could say they are exceptions to what the program was intended for. I would also say that exceptions in the programming sense are anything that needs to be handled in a way different from the general case, which includes some, but is not limited to, errors. Some errors can't be handled.
Exception handling can be used for more than just catching undesirable effects.
While this is not a very detailed answer, at least it points out that they are not equivalent.
If all Zims are Zoms and all Zigs are Zoms, are all Zims also Zigs? Are all Zigs also Zims?