title: Avoiding nested try/catch
body: <pre><code>import java.util.Scanner;
  
  public class Test{
  
      public static void main(String[] args){
  
      Scanner input = new Scanner(System.in);
      String str = input.next();
      int a;
      try{
          try{
              a = Integer.parseInt(str);
          }
          catch(NumberFormatException nfe){
              throw new CustomException("message");
          }
          if (a&gt;50) throw new CustomException("message");
      }
      catch(CustomException e){
          //do something
      }
  }
  }
  </code></pre>
  
  <p>If <code>str</code> is something other than numbers, <code>parseInt</code> will throw a <code>NumberFormatException</code>. But I want to 'convert' it so that I'll have a <code>CustomException</code> with "message" instead. Can I do this without using a nested <code>try/catch</code> blocks like above?</p>