title: How to use variable from an If-Else statement inside Try-Catch (Java)
body: <p>How to use a variable from an if-else statement inside Try-Catch in Java?</p>
  
  <pre><code>String value1 = "sample"; 
  String value2 = "sample";
  int a=0;
  
  try 
  {
  
      if(value2.equals(value1))
      {
          a = 1;
      }
       int b = a;
  
  catch (Exception e)
  {
      System.out.println("Update Error!");
  }
  </code></pre>
  
  <p>The <code>a</code> in <code>int b = a;</code> has an error that says "Variable might not have been initialized". How do I use that variable?</p>