I'm trying to create a custom exception for my program but when go to extend the exception class i get two errors
I created a method called fileNotFoundException(String m) and i tried to put super(m); inside of it but when I do that it gives me the error "Constructor call must be the first statement in a constructor". But when I do it outside the method it's fine. Also when I create the method they make me put void. I'm watching a video about creating custom exception errors and they had none of those problems. They didn't have to put a return type and they were able to put super() inside of the method with no problem.
fileNotFoundException(String m)
super(m);
super()
What am i doing wrong that makes it throw errors like that?
code:
public class WrongFileSelcException extends Exception { public fileNotFoundException(String m) { super(m); } }
video: https://www.youtube.com/watch?v=KFoN6hQ3yAs
The constructor must take the same name as the class to which it belongs. You need:
public class WrongFileSelcException extends Exception { public WrongFileSelcException(String m) { super(m); } }
2.1m questions
2.1m answers
60 comments
57.0k users