Questions tagged [throws]

throws is a Java keyword. It is used in a method definition to declare the Exceptions to be thrown by the method.

Java distinguishes between checked and unchecked exceptions. Unchecked exceptions (RuntimeException, Error, and their subclasses) can be thrown without restriction. But if a method can generate a checked exception, the compiler requires that it either be caught (with a try/catch block) or declared in the method signature with the throws keyword.

https://en.wikibooks.org/wiki/Java_Programming/Keywords/throws https://docs.oracle.com/javase/tutorial/essential/exceptions/declaring.html

249 questions
-2
votes
2 answers

What is the loss without throws in java?

I have googled and read many answers on try,catch and throws. I still cannot get my question answered. My question is, we try a code and if exception occurs, the execution terminates right away and catch takes care of the rest. In fact we define…
Shridhar
  • 333
  • 1
  • 3
  • 15
-2
votes
4 answers

How does throws work at Java?

I have been using catch and now I have to use throw. This is what I 've been given and I can't figure out what's missing so that it will work. public static void main(String args[]){ Exception_Tester et = new Exception_Tester(); int…
-2
votes
5 answers

Throw keyword in Java

In Java, is the keyword (throw) only used for throwing exception that you've created. If not, can someone give an example of how it is used outside of your own made exceptions.
TBNRsiyi
  • 23
  • 1
  • 4
-3
votes
1 answer

to create our own custom exception, throw or throws or try & catch?

in Java If we want to create our own custom exception, which keyword should we use? throw or throws or try & catch?
saboor
  • 23
  • 3
-3
votes
1 answer

Can anyone please correct my given statement if its wrong(about throw/throws)

THROW:-We have to handle the exception(we in the sense user here). Throws:We are asking the compiler to handle the exception raised. Please correct if what I stated above is wrong . If wrong please tell me the correct statement. Thanks in Adv!
user3300851
  • 87
  • 1
  • 3
  • 12
-3
votes
6 answers

try/catch in throws function

If I put a try/catch in a throws function, in case of an exception which one runs? Does it do whatever in catch clause, throws an exception or both? Adding some more details, what if the exception in the inner scope is inherited form the other or…
-4
votes
1 answer

c++ array [] operator throws not working

Okay, so I created some throws for my safeArray::operator[], but the throws only work for certain numbers -- the other numbers cause the program to crash for some reason. At the moment if I have: if (index < startingIndex) { try …
Trevor
  • 7
  • 3
-4
votes
1 answer

Java - Exception handling - throws

I know javac forces the programmer to handle checked exceptions which need to be thrown by the method or handled using try-catch/finally. And it will not stop programmer from throwing an unchecked exception. I also know why we do try-catch/finally…
Venkataswamy
  • 1,019
  • 7
  • 7
-4
votes
5 answers

Android (or Java perhaps) unfamiliar "throw" usage

I found an unfamiliar usage of "throws" in Android sample code like below. public Void handleResponse(HttpResponse response) throws IOException { ... } I just want to know how this "throws" works in this case. I posted this since it was a bit…
1 2 3
16
17