Exception Management

  • Thread starter Thread starter Bijoy Naick
  • Start date Start date
B

Bijoy Naick

I have an asp .net application where a user can click a button to
retrieve certain data.

The structure of the onClick handler is as follows:

Protected Sub button_click(blah blah)
Try
run some queries
call FindSomeData()
display confirmation message
Catch ex Ass Exception
display error 1
End Try
End Sub

Private Sub FindSomeData(ByVal key as integer, ByRef returnVal As
String, ByRef returnKey As Int)
Try
run a query
massage the data
Catch ex Ass Exception
display error 2
End Try
End Sub

If an exception were raised in FindSomeData, I would except the "display
error 2" to execute and the page to stop executing. However, what
happens is that "display error 2" is executed, but control returns to
the onclick sub and the confirmation message is also displayed..

Is this expected functionaility? How can i get the page to display error
2 and then stop execution?

Thanks in advance.

Bijoy

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
When you catch an Exception, you do exactly that: catch it. It no longer
stops execution, but instead does what your Exception Handler says to do. If
you want it to cause the Page to stop execution, throw it in your Catch
block. Example:

Try
...
Catch ex As Exception
...
Throw ex
End Try

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
I typically implement something like this: basically just turn FindSomeData
from a sub into a function that returns whether or not it threw an
exception.

Protected sub button_click(blah blah)

Try
run some queries
If FindSomeData() Then
display confirmation message
End If
Catch ex As Exception
display error 1
End Try

End Sub

Private FUNCTION FindSomeData(ByVal key as integer, ByRef returnVal As
String, ByRef returnKey As Int) as BOOLEAN

Try
run a query
massage the data
Return True
Catch ex As Exception
display error 2
Return False
End Try

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top