How to throw RuntimeException ("cannot find symbol")
An Exception
is an Object
like any other in Java. You need to use the new
keyword to create a new Exception
before you can throw
it.
throw new RuntimeException();
Optionally you could also do the following:
RuntimeException e = new RuntimeException();
throw e;
Both code snippets are equivalent.
Link to the tutorials for completeness.
throw new RuntimeException(msg);
You need the new
in there. It's creating an instance and throwing it, not calling a method.