title: JAVA: "error: unreported exception Exception; must be caught or declared to be thrown"
body: <p>I am new to programming in JAVA and got stuck in code where I need to print the the exponential result of two non-negative numbers. In case if any of them is negative, I need to throw an exception, my code is as follows:`</p>
  
  <pre><code>import java.util.*;
  import java.util.Scanner;
  
  class MyCalculator {
  
      int power(int n, int p) {
          int result = 1;
          if (n &lt; 0 || p &lt; 0) {
              throw new Exception("n and p should be non-negative");
              else
          {
          while(p!=0)
              {
              result=result*n;
              p-=1;
          }
          return result;
      }
          }
      }
  
      class Solution {
  
          public static void main(String[] args) {
              Scanner in = new Scanner(System.in);
  
              while (in.hasNextInt()) {
                  int n = in.nextInt();
                  int p = in.nextInt();
                  MyCalculator my_calculator = new MyCalculator();
                  try {
                      System.out.println(my_calculator.power(n, p));
                  } catch (Exception e) {
                      System.out.println(e);
                  }
              }
          }
      }
  </code></pre>
  
  <p>I am getting the above written error IE:</p>
  
  <pre><code>error: unreported exception Exception; must be caught or declared to be thrown
  </code></pre>
  
  <p>I needed a conceptual understanding of what actually is causing this error to occur.</p>