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,
 
Try Int32.Parse("test") instead of Convert.ToInt32 and see if it works
 
The same result, since Convert.ToInt32() internally calls Int32.Parse()....
:-(
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top