0

I am trying to throw custom exceptions in a class, however I keep getting symbol not found even though I have defined a custom exception which extends from exception. Both this class and the exception are in the same package and directory so I do not understand why it doesn't work.

public class Account {
ArrayList<String> accountArray = new ArrayList<String>();
ArrayList<Integer> idArray = new ArrayList<Integer>();

private int createAccount(String handle) throws IllegalHandleException, InvalidHandleException {
    if (!accountArray.contains(handle)) {
        if (handle.length() > 0 && handle.length() < 30 ){
            if (!handle.contains("  ")) {
                accountArray.add(handle);
                int id = accountArray.indexOf(handle);
                idArray.add(id);
                return id;
            } else {
                throw new IllegalHandleException();
            }
        } else {
            throw new IllegalHandleException();
        }
    } else {
        throw new InvalidHandleException();
    }
   }
 }

Both of the exceptions (IllegalHandle and InvalidHandle) extend exception and call its constructor, they dont add any of their own code.

Ad270
  • 13
  • 4

0 Answers0