If I had to guess what was happening based on the piece of code you posted, the error is probably caused by the fact that you are trying to throw a ParenthesisException from the static method.
In Java, classes defined inside another class automatically store a pointer to the object within which they were created. That is, a ParenthesisException has an implicit pointer back to the surrounding class, inside which it was created using new . This means that, in particular, you cannot build a new ParenthesisException inside the static method, because there is no this pointer that can be used to refer to the containing class.
To fix this, you should make the inner class ParenthesisException a static as follows:
private static class ParenthesisException extends Throwable { public ParenthesisException(){} public String strErrMsg() { return "ERROR: Every '(' needs a matching ')'"; } }
This static after private says that ParenthesisException does not contain a link back to the object object, which you probably want anyway. It also means that you can new ParenthesisException inside static methods.
Hope this assumption is correct, and hope this helps!
source share