Question: I'm attempting to describe running ec2 instances that I'm using with the following code:

```
DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
            List<Reservation> reservations = describeInstancesRequest.getReservations();
            Set<Instance> instances = new HashSet<Instance>();

            for (Reservation reservation : reservations) {
                instances.addAll(reservation.getInstances());
            }

            System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running.");

```

I'm getting a return result of 0. I'm guessing this is because the default AZ is set to US-East.

My instances are running in US-West.

How do I change the AZ?

Answer: 
What happen if the cell doesn't contain a valid number (for example an empty string)?.  

You get the exception mentioned in your question.  

A simple workaround is to use the [TryParse](http://msdn.microsoft.com/en-us/library/f02979c7.aspx) method 

```
int renewalGracePeriodDays;
string temp = row.Cells.FromKey(COL_RENEWAL_GRACE_PERIOD_DAYS).Text;
Int32.TryParse(temp, out renewalGracePeriodDays);

```

From the MSDN docs

> 
> When this method returns, *[the second parameter]* contains the 32-bit signed integer value
>  equivalent to the number contained in s *[the first parameter]*, if the conversion succeeded,
>  or **zero if the conversion failed**. The conversion fails if the s
>  parameter is null, is not of the correct format, or represents a
>  number less than MinValue or greater than MaxValue. This parameter is
>  passed uninitialized
> 
> 
> 

Bold and text in square brakets have been added by me. So if your default value should be zero you don't have to do any test on the result of the TryParse method.
It's possible that the column you are checking is either an empty string, or contains non-integer data. I recommend using the TryParse method.

```
int renewalGracePeriodDays;
if (!int.TryParse(row.Cells.FromKey(COL_RENEWAL_GRACE_PERIOD_DAYS).Text), out renewalGracePeriodDays)
{
    renewalGracePeriodDays = 0;
    // Inside here, you can log the exception, alert the user, or end processing
}

```

If the TryParse fails, your grace period will default to 0. It's a good idea to use this method when dealing with user inputs, because there's no telling what people will enter, even when properly prompted...