0

I'd like to process user input and throw an Exception if it exceeds some fixed limit of character. Example:

public String read(Reader r){
    String input;
    //get the input
    if(input.lenght() > 100)
         //throw what?
    return input;
}

Should I craft my own exception class for that case? I presume that just using IllegalArgumentException would not be fine.

Alupkers
  • 223
  • 1
  • 9

1 Answers1

1

You will have to make your own Exception

Refer: How to create custom exceptions in Java?

Try this:

public String read(Reader r){
    String input;
    //get the input
    if(input.lenght() > 100)
         throw new Exception("Write your own stuff");
    return input;
}
Community
  • 1
  • 1
Tilak Madichetti
  • 4,110
  • 5
  • 34
  • 52