Back
I am trying to implement a class from my java file and it is giving me an error like this:
error: unreported exception IOException; must be caught or declared to be thrown
Does anyone know any way to throw the exception?
You can throw your exception in two ways:
Throw the exception outside the method
public void Somemethod() throws IOException{//code here}
public void Somemethod() throws IOException{
//code here
}
Catch the exception
public void Somemethod(){try{//somecode}catch(IOException e){//handle the exception}
public void Somemethod(){
try{
//somecode
}catch(IOException e){
//handle the exception
Want to learn Java? Check out the Java certification from Intellipaat.
31k questions
32.8k answers
501 comments
693 users