Force Guid.Parse to Throw OverflowException

  • Thread starter Thread starter jehugaleahsa
  • Start date Start date
J

jehugaleahsa

Hello:

I am trying to write a test that captures OverflowException being
thrown when calling Guid.Parse. Microsoft says it can happen, but I
don't know how to make it.

Does anyone have a snippet of code that will always result in the
exception being thrown? I'd appreciate it.

Thanks,
Travis
 
I am trying to write a test that captures OverflowException being
thrown when calling Guid.Parse. Microsoft says it can happen, but I
don't know how to make it.
There is no Guid.Parse() method. The Guid class has constructors for
parsing. I'm going to assume you mean those.

As far as I can tell, these constructors cannot throw OverflowException as
they're currently (CLR 2.0 SP2) implemented. However, just because the
specification says this exception is possible doesn't mean the current
implementation has to have any path for generating one. Whether it means
client code should still catch it depends on how much you're willing to
stake on this remaining so in the future.
 
There is no Guid.Parse() method. The Guid class has constructors for
parsing. I'm going to assume you mean those.

As far as I can tell, these constructors cannot throw OverflowException as
they're currently (CLR 2.0 SP2) implemented. However, just because the
specification says this exception is possible doesn't mean the current
implementation has to have any path for generating one. Whether it means
client code should still catch it depends on how much you're willing to
stake on this remaining so in the future.

Thanks. I did mean the Ctors. I guess I won't worry about it, then.

Thanks!
 
Thanks. I did mean the Ctors. I guess I won't worry about it, then.

Thanks!
Hi,

I took a look in Reflector and it seems OverflowException can come if You
use the "{0xdddddddd, 0xdddd,
0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}} " format to specify the
Guid. Try this one to get Your desired exception :
{0x00000000, 0x0000,
0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x123456789ABC}}
(notice the last part wont fit into a byte...)

Hope You find this useful.
-Zsolt
 
Hi,

I took a look in Reflector and it seems OverflowException can come if You
use the "{0xdddddddd, 0xdddd,
0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}} " format to specify the
Guid. Try this one to get Your desired exception :
{0x00000000, 0x0000,
0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x123456789ABC}}
(notice the last part wont fit into a byte...)

Hope You find this useful.
-Zsolt- Hide quoted text -

- Show quoted text -

Awesome...
 
Back
Top