Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

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?

1 Answer

0 votes
by (13.1k points)

You can throw your exception in two ways:

  1. Throw the exception outside the method

public void Somemethod() throws IOException{

//code here

}

  1. Catch the exception

public void Somemethod(){

try{

//somecode

}
catch(IOException e){

//handle the exception

}

Want to learn Java? Check out the Java certification from Intellipaat. 

Related questions

0 votes
1 answer
asked Mar 28, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 20, 2020 in Java by angadmishra (6.5k points)
0 votes
1 answer

Browse Categories

...