|
-
Mar 20th, 2003, 03:58 PM
#1
Thread Starter
Frenzied Member
Newbie: Unhandled Exceptions
As I learn vb.net, I rely on the exception messages my bad code generates to figure out what's going on. Sometimes, though, something is wrong and no exception is raised - instead, the remainding code in the sub doesn't execute and the program continues. This makes it harder for me to debug.
For example, this happens if I try to do a SqlDataReader.Read() against a closed connection.
Now if I wrap the code inside a Try block, I can catch the exception, display the Message and learn something.
What I'm wondering is why some unhandled exceptions pop up a box saying my code has created a problem and others (like in the above example) are simply ignored.
As I'm not sure what other scenerios may behave the same way, I'm wondering if it would be a good idea to wrap every sub inside a try block.
I'm very new at vb.net, and information is appreciated.
Mike
-
Mar 20th, 2003, 04:42 PM
#2
PowerPoster
Errors bubble up if you don't have an error catch on that statment. So lets say you call a method inside a try block. Inside that method, another method is called, but it isn't within a try catch block. If that creates an error, the method will stop, and the error will be bubbled up to the first try catch block found up the call stack. If it reaches the top with no error catching, then you will see an error message.
Maybe another try catch block is catching the error and you don't realize it.
-
Mar 20th, 2003, 05:05 PM
#3
Thread Starter
Frenzied Member
ok - got that. Does that explain what's happening in the following situation?
I know I have have a problem inside a sub - so I do a run to cursor to the beginning of that sub. Then I F11 through it. When I get to a line that assignes a SqlDataReader to a SqlCommand.ExecuteReader (the command's connection has not been opened) the sub just quits - that is, no more code is executed and the program continues just fine.
Putting a try block around that offensive line of code traps the error and Exception.Message says something to the effect that the connection must be open.
I could see where ExecuteReader could squelch an exception (although I hope not), but even if that was the case, wouldn't the remaining code in the sub get executed?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|