Throwing Some Throws
In this lesson, we'll walk through the syntax and usage of the throws keyword.
We'll cover the following...
Declaring throws
The throw keyword is mainly used in a method’s body. We can use the throw keyword multiple times.
However, we can also declare exceptions in the method’s signature using another keyword, i.e, throws
.
Press + to interact
class Exceptions {public static void main( String args[] ) {readFile("filename.text");}public static void readFile(String path) throws RuntimeException{ //UncheckedException//code hereSystem.out.println("Reading File");}}
Here, ...