What is the standard exception to throw in Java for not supported/implemented operations?

Viewed 208855

In particular, is there a standard Exception subclass used in these circumstances?

5 Answers

If you want more granularity and better description, you could use NotImplementedException from commons-lang

Warning: Available before versions 2.6 and after versions 3.2 only.

The below Calculator sample class shows the difference

public class Calculator() {

 int add(int a , int b){
    return a+b;
  }

  int dived(int a , int b){
        if ( b == 0 ) {
           throw new UnsupportedOperationException("I can not dived by zero, 
                         not now not for the rest of my life!")
        }else{
          return a/b;
       }
   }

   int multiple(int a , int b){
      //NotImplementedException from apache or some custom excpetion
      throw new NotImplementedException("Will be implement in release 3.5");
   } 
}
Related