Wednesday 15 January 2014

c++ - Simple "catching" logic -


I have a string that is changing to the UIT 32 in the code below:

  Try {int newX = System :: Convert :: ToUInt32 (this-> cbXSizeBox-> Text); } Hold (FormatException ^ E) {printf ("\ n is not a valid 3-digit number"); It-> cbXSizeBox-> Text = System :: Convert :: ToString (capBoxSize-> x); }   

This works fine. (FII cap boxes-> X is another value that can be evaluated in UIT 32).

Actually CBXSizeBox - & gt; The text (which is a string) should be returned to its basic value, the user should enter anything but numbers (for example 2g9).

In the event that the catch block format does not take exception, I call it capbox-size-> for the new valid value. I would like to add code to change the value of x, I'm trying to do something that says to the compiler, "If you catch this exception, then do so. But if you do not catch exception, do so. " Is it possible to wrap a catch block in another statement?

If you understand what I am trying to do, then any suggestions will be appreciated.

Try the capbox-size-> Putting the code to change x is not really an option which I think. Since this can try to designate the new xbox "2ty" as something like capboxing-> x, which is UIT 32.

No need for any else block , Just put the formatting after the reality parsing:

  Try {int newX = System :: Convert :: ToUInt32 (this-> cbXSizeBox-> Text); Capboxesis-> X = newX; } Hold (FormatException ^ E) {printf ("\ n is not a valid 3-digit number"); It-> cbXSizeBox-> Text = System :: Convert :: ToString (capBoxSize-> x); }   

No need for temporary newX , just specify it directly:

  capBoxSize- & gt; X = System :: Convert :: ToUInt32 (this-> cbXSizeBox-> Text);   

try the capBoxSize-> in the block Entering code to replace x is not really an option which I feel as it might try to designate the new Xbox as "something like" capboxing-> X, which is UIT 32.

It will never happen because at this point your code has already entered an exception and as a result the code left is left and catches entered> block.


He said, to avoid try > catch and instead of system :: will use Int32 :: TryParse

No comments:

Post a Comment