0

If I create custom exception with a String message i have: super(message) however, i want to have a double number in my exception message. The constructor will be something like myException: my message:90.6. throw exception: throw new myException("my message", 90.6);

Here is the code i've tried but didnt works. Any help would be much appreciate.

public class myException extends Exception {

    private String message;

    private double qtyAvail;

    public myException(String message, double qtyAvail){

        super(message);

        this.qtyAvail = qtyAvail;

    }
2
  • 4
    And why didn't it work? Commented May 4, 2013 at 10:08
  • You don't need message field. Commented May 4, 2013 at 10:21

1 Answer 1

4

Why don't you do

public MyException(String message, double qtyAvail){
    super(message + " " + qtyAvail);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.