• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

catch both sqlException and normal exception

I have a function which makes a call to the database

now I catch the sqlException, however in my CATCH block, i want to catch the 'normal' exception as well and have two different actions which I do when either of the two occurs

how do i do it ?
0
manivineet
Asked:
manivineet
1 Solution
 
ajitha75Commented:
try
{
....do something
}
catch(SqlException ex)
{
...SQL Exception here
}
catch(Exception ex)
{
.... Normal Exception here..

}

Thanks
Ajitha
0
 
CSecurityCommented:
Try
[Do some sql stuff here which might have exception]

Catch exp As SqlException
MsgBox(exp.Message, MsgBoxStyle.Critical, "SQL error")

Catch exp As Exception
MsgBox(exp.Message, MsgBoxStyle.Critical, "General error")

End Try
0
 
jorge_torizCommented:
Nop, you can't... you can use the innerException and stack from the exception but you can't catch the exception twice, the framework doesn't work in that way
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CSecurityCommented:
ajitha75, it's VB.NET, not C# :)
0
 
appariCommented:
you can try like this
try
....
....
Catch ex As Exception
            If TypeOf ex Is SQLClient.SQLException Then
                MessageBox.Show(ex.Message)
            End If
            MessageBox.Show(ex.Message)
End Try
0
 
ROMA CHAUHANProject LeadCommented:
0
 
shrinivasmwCommented:
string errMsg = "" ;
try
{
//
}
catch(SqlException excp)
{
errMsg = "Database error: " + excp.Message  ;
}
catch(Exception ex)
{
errMsg = "Application error: " + excp.Message  ;
}

Please let me know if this works.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now