Skip to main content
added 316 characters in body
Source Link
Ben Aaronson
  • 7k
  • 1
  • 31
  • 30

What if your code was:

try
{
   MethodThatMightThrow();
   var firstVariable = 1;
}
catch {}

try
{
   var secondVariable = firstVariable;
}
catch {}

Now you'd be trying to use an undeclared and uninitialized variable (firstVariable) if your method call throws.

Note: The above example specifically answers the original question, which states "consistency-sake aside". This demonstrates that there are reasons other than consistency. But as Peter's answer shows, there is also a powerful argument from consistency, which would for sure have been a very important factor in the decision.

What if your code was:

try
{
   MethodThatMightThrow();
   var firstVariable = 1;
}
catch {}

try
{
   var secondVariable = firstVariable;
}
catch {}

Now you'd be trying to use an undeclared and uninitialized variable (firstVariable) if your method call throws.

What if your code was:

try
{
   MethodThatMightThrow();
   var firstVariable = 1;
}
catch {}

try
{
   var secondVariable = firstVariable;
}
catch {}

Now you'd be trying to use an undeclared variable (firstVariable) if your method call throws.

Note: The above example specifically answers the original question, which states "consistency-sake aside". This demonstrates that there are reasons other than consistency. But as Peter's answer shows, there is also a powerful argument from consistency, which would for sure have been a very important factor in the decision.

added 18 characters in body
Source Link
Ben Aaronson
  • 7k
  • 1
  • 31
  • 30

What if your code was:

try
{
   MethodThatMightThrow();
   var firstVariable = 1;
}
catch {}

try
{
   var secondVariable = firstVariable;
}
catch {}

Now you'd be trying to use an undeclared and uninitialized variable (firstVariable) if your method call throws.

What if your code was:

try
{
   MethodThatMightThrow();
   var firstVariable = 1;
}
catch {}

try
{
   var secondVariable = firstVariable;
}
catch {}

Now you'd be trying to use an undeclared variable (firstVariable) if your method call throws.

What if your code was:

try
{
   MethodThatMightThrow();
   var firstVariable = 1;
}
catch {}

try
{
   var secondVariable = firstVariable;
}
catch {}

Now you'd be trying to use an undeclared and uninitialized variable (firstVariable) if your method call throws.

What if your code was:

try
{
   MethodThatMightThrow();
   var firstVariable = 1;
}
catch {}

try
{
   var secondVariable = firstVariable;
}
catch {}

Now you'd be trying to use an undeclared variable (firstVariable) if your method call throws.

What if your code was:

try
{
   MethodThatMightThrow();
   var firstVariable = 1;
}
catch {}

try
{
   var secondVariable = firstVariable;
}
catch {}

Now you'd be trying to use an undeclared variable if your method call throws.

What if your code was:

try
{
   MethodThatMightThrow();
   var firstVariable = 1;
}
catch {}

try
{
   var secondVariable = firstVariable;
}
catch {}

Now you'd be trying to use an undeclared variable (firstVariable) if your method call throws.

Source Link
Ben Aaronson
  • 7k
  • 1
  • 31
  • 30
Loading