views:

86

answers:

2

Hey guys,

When I do the try/catch method in my vb.net project I will try the code I want and when it can't do it, i make a message box right after the catch method. The thing is that it will show the message box, and then another message from the program itself. Like for example, I have here a MySQLException, and when i click ok on the message box, it will show another one right after showing the exception itself. How would I be able to get rid of this so the user doesn't have to see this, and the program can continue.

Thanks,

kevin

A: 

Try this. It should only display one message. Make sure your original message is coming from a statement after the Try.

Try
  code
Catch ex as exception
  call msgbox (ex.message)
end try
xpda
A: 

It sounds like you're actually getting more than one exception. Have you checked the stack traces for both errors?

What I think is happening is that your first function is throwing the MySQLException and then returning nothing. You're then probably getting a NullReferenceException from whatever made the call to the database.

Your best bet is to not catch some many exceptions. Your data layer should be free of Try/Catch blocks unless you're trying to cater for something very specific. Your business layer should then catch any other non-general exceptions that occur specific to the functionality there. Finally, your application layer should be handling all of your general exceptions and reporting on them from there.

Sonny Boy