exceptions

Kurt

Regular
Joined
Feb 14, 2003
Messages
99
Location
Copenhagen
Little problem... when reaching a runtime error, the program doesn't seem to break giving me a warning that something is wrong and leaving me the choice to break the program or to continue it, but just leaves the sub/function where the exception is thrown.

eg. Suppose the following line is reached and the value of me.txtTextbox.text = "a"

Visual Basic:
myInt = convert.ToInt32(me.txtTextbox.text)

The running program doesn't inform me about this problem!!! The routine containing that line is just left....

If I put however

Visual Basic:
try
    myInt = convert.ToInt32(me.txtTextbox.text)
catch e as exception
    msgbox("something wrong.")
end try

the messagebox is displayed.

I know for sure that some time ago, without having the try-block, I would have had a message box coming up asking me to continue or to break the program. When I selected break, I would be shown the line with the problem. Is there a general setting in the IDE that influences this? I use Visual Studio .NET...
 
The program will not break if the error is handled by a Try...Catch, it should come up with error if there is not Try...Catch around it
 
That's the problem.... it does not break without a Try Catch, no message box is even shown at all. So it took me a while before I even noticed that some part of the code (starting from myInt = convert.ToInt32(me.txtTextbox.text) for example) never executed. The routine is just left....
 
And in some of the projects I work on, behaviour is as expected. A message box pops up asking to break or continue.... It's just that in some other projects this is not the case. And this is not about nested error handling blocks....
 
Kurt,

Do you have any other Try Catch blocks in your application? You may have one higher up in the code which is wrapped around the function that executes myInt = convert.ToInt32(me.txtTextbox.text).
 
no, no nested error handlers... Besides, when I execute the program step by step with the debugger, no jump to any Catch block is made. The routine is left when the line is reached, and that's it. The program keeps running.
 
Are you sure you aren't calling any methods that have try catch in them without warnings?
Try setting the program to debug if it isn't already.
What OS is this on?
Can you show us the actual code?
Are you saying that the code below your problem area in the method is just skipped when there is a problem?
 
help....

Yes, the code is skipped. This is both the case on my Windows 2000 and Windows XP systems. I just changed in the exceptions dialogue box (file menu Debug --> Exceptions) that my debugger should break when the exception is thrown, rather than when the exception is unhandled. In that case the break comes 2 times.....

1./ A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.

2./ A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in system.windows.forms.dll
Additional information: Exception has been thrown by the target of an invocation.

The second break is a little strange to me, because when I test the line

Visual Basic:
dim int as int32 = convert.toint32("a")

in another project then I get the same first message (after changing the exception settings), but the following message says;

2./ An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.

and when I try to continue, the program is stopped, as expected. But in the real project, after the seconde 'first chance' message, the program keeps running... no 'unhandled exception' message comes, and the code under the problem is skipped. By the way, what is this TargetInvocation???
 
Maybe it would be a good idea to post the whole app just to see if someone else gets the same result. Although I could not run it, someone else here could.
 
Back
Top