T
Tylius
This one line is causing the issue, I've searched all over the net, but I
can't seem to figure out why
public static void Main(string[] args)
{
Console.WriteLine("Dice Roller");
try
{
int num_dice = int.Parse(args[0]); // This is the problem
this is the error I get:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
Actually this works when I run the executable with 2 arguments, but I'm
curious as to why it's crashing when I don't input anything, because I
placed the exception-handling code in there, I must be doing something
wrong, here's the code:
public class DiceRoller
{
public static void Main(string[] args)
{
Console.WriteLine("Dice Roller");
try
{
int num_dice = int.Parse(args[0]);
int num_sides = int.Parse(args[1]);
Console.WriteLine("Now rolling: {0}d{1}", num_dice, num_sides);
Console.WriteLine("Total Roll: {0}", RandomNumber(num_dice, num_sides));
RandomNumber(num_dice, num_sides);
} catch (System.FormatException)
{
Console.WriteLine("Please enter two numeric arguments");
Console.WriteLine("Usage: <Number of Dice> <Number of Sides>");
} catch (Exception e)
{
Console.WriteLine("An error has occured, displaying contents now...\n");
Console.WriteLine(e);
}
}
Anyone have any ideas for me? I'm still new to C#, and I'm guessing this is
just a simple mistake on my part, any help would be greatly appreciated
can't seem to figure out why
public static void Main(string[] args)
{
Console.WriteLine("Dice Roller");
try
{
int num_dice = int.Parse(args[0]); // This is the problem
this is the error I get:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
Actually this works when I run the executable with 2 arguments, but I'm
curious as to why it's crashing when I don't input anything, because I
placed the exception-handling code in there, I must be doing something
wrong, here's the code:
public class DiceRoller
{
public static void Main(string[] args)
{
Console.WriteLine("Dice Roller");
try
{
int num_dice = int.Parse(args[0]);
int num_sides = int.Parse(args[1]);
Console.WriteLine("Now rolling: {0}d{1}", num_dice, num_sides);
Console.WriteLine("Total Roll: {0}", RandomNumber(num_dice, num_sides));
RandomNumber(num_dice, num_sides);
} catch (System.FormatException)
{
Console.WriteLine("Please enter two numeric arguments");
Console.WriteLine("Usage: <Number of Dice> <Number of Sides>");
} catch (Exception e)
{
Console.WriteLine("An error has occured, displaying contents now...\n");
Console.WriteLine(e);
}
}
Anyone have any ideas for me? I'm still new to C#, and I'm guessing this is
just a simple mistake on my part, any help would be greatly appreciated