How to define custom exception class in Java, the easiest way?

Posted by yegor256 on Stack Overflow See other posts from Stack Overflow or by yegor256
Published on 2010-09-23T07:51:14Z Indexed on 2012/11/19 5:01 UTC
Read the original article Hit count: 131

Filed under:

I'm trying to define my own exception class the easiest way, and this is what I'm getting:

public class MyException extends Exception {}

public class Foo {
  public bar() throws MyException {
    throw new MyException("try again please");
  }
}

This is what Java compiler says:

cannot find symbol: constructor MyException(java.lang.String)

I had a feeling that this constructor has to be inherited from java.lang.Exception, isn't it?

© Stack Overflow or respective owner

Related posts about java