What is the difference between throw and throws? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

What is the difference between throw and throws?

throw and throws are the keyword

11th Apr 2017, 10:06 AM
Bineeta Rawat
Bineeta Rawat - avatar
4 Respostas
11th Apr 2017, 10:11 AM
ą¤¦ą„‡ą¤µą„‡ą¤‚ą¤¦ą„ą¤° ą¤®ą¤¹ą¤¾ą¤œą¤Ø (Devender)
ą¤¦ą„‡ą¤µą„‡ą¤‚ą¤¦ą„ą¤° ą¤®ą¤¹ą¤¾ą¤œą¤Ø (Devender) - avatar
+ 1
public class A { public void testA throws Exception ( ){ } public void testB ( ) { throw new Exception ( ) ; } public static void main ( String [ ] args ) { A a = new A ( ) ; // a.testA ( ) ; // compile error. try { a.testA ( ) ; // the method must be inside the try scope. catch ( Exception e ) { e.printStackTrace ( ) ; } } }
11th Apr 2017, 10:29 AM
K.C. Leung
K.C. Leung - avatar
+ 1
you use throw when you want to throw an execption as statement, you use throws when you mark a method that may throw an execption for warning user to handle that exception witg try and catch
11th Apr 2017, 11:42 AM
Ī·=sqrt(Ī¼/Īµ)
Ī·=sqrt(Ī¼/Īµ) - avatar
0
Thx. The answers helped me too!
4th May 2017, 8:19 PM
Lisa TĆ¼rk
Lisa TĆ¼rk - avatar