You may need to do some digging... If you try this test code block as a windows console app you'll see that what is happening in your test code is that the value is wrapping. i.e. When it is invalid, it wraps as a negative value. That means you are doing something different in the code that is failing as opposed to the code that works as this does.
class Program
{
static void Main(string[] args)
{
int j = Int32.MaxValue;
int r = 0;
int i = 0;
Random rnd = new Random(10000);
try
{
r = rnd.Next();
for (i = 0; i < 10; i++)
{
Console.Write(
String.Format( "i={0}, j={1}, r={2}:
result=", i, j, r ));
j *= r;
Console.WriteLine( j );
}
}
catch( Exception err )
{
Console.WriteLine(
String.Format( "Error( i={0}, j={1}, r={2} ):
{3}", i, j, r, err.Message ));
}
Console.WriteLine( string.Empty );
Console.WriteLine( "Press Any Key To Continue");
Console.ReadKey();
}
}