why doesn't it land in may catch

  • Thread starter Thread starter Maersa
  • Start date Start date
M

Maersa

Hi,

I have the following code, but can't catch the exception..

try
{
Int32 v =
(Int32)TypeDescriptor.GetConverter(typeof(int32)).ConvertFromString(
"test" );
// Int32 v = Convert.ToInt32( "test" );
}
catch( Exception e )
{
throw new Exception( e.Message, e );
}

Appreciate your help.

thanks,
 
When you say "test" I suppose the string is something like "1234" ..... ?
if you really use the string "test", of course it won't work :)

ROM
 
Yes, that's why I got the try...catch ... but the exception thrown by
Int32.Parser can't be "caught"....
 
The code below doesn't compile - the fragment typeof(int32) should be
typeof(Int32).

Once I changed that it ran and threw an exception which was caught.
The line
// Int32 v = Convert.ToInt32( "test" );
wont throw an exception because you've got it commented out - it never
compiled into IL.

If you uncomment that line and comment out the line above it it wil throw an
exception which is caught.

You must not be testing your code correctly.
 
Back
Top