From the following code fragments select the most appropriate way of throwing exceptions ?Assume that variable i is properly defined , in scope and has appropriate value

  1. if ( i > 10) { throws new IndexOutOfBoundsException("Index is out of bound!"); }

  2. if ( i > 10) { throw new IndexOutOfBoundsException("The value of index i=" + " is out of bound!" ); }

  3. if ( i > 10) { throw "Index is out of bound!"; }

  4. None of the ABove


Correct Option: B

Find more quizzes: