Questions tagged [unchecked-exception]

In Java programming, an exception that does not need to be declared in a method's throws clause, and is not required to be caught.

RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.

RuntimeException and its subclasses are unchecked exceptions. Unchecked exceptions do not need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.

Details: http://docs.oracle.com/javase/7/docs/api/java/lang/RuntimeException.html

63 questions
0
votes
0 answers

Removing unchecked exception in Java without supressing the warning

I have a method that does comparison of two jsons. import org.json.JSONException; import org.junit.Test; import org.skyscreamer.jsonassert.*; import org.skyscreamer.jsonassert.comparator.CustomComparator; public class TestClass { @Test …
Saffik
  • 911
  • 4
  • 19
  • 45
0
votes
1 answer

Why JVM does not allow to throw Unchecked Exception from static block?

Why JVM does not allow to throw Unchecked Exception from static block? But it still allows them implicitly (e.g: calling method on null object). Note: The question is more academic and not from real life issue.
0
votes
2 answers

Guava Preconditions RuntimeExceptions handling

As I understood, we use Guava Preconditions to fail fast, before changing some objects states (a nice answer here from stackoverflow). And this is good. However it throws Runtime exceptions and this is not the favorite exceptions for the user of an…
Farah
  • 2,469
  • 5
  • 31
  • 52
0
votes
1 answer

returning java.util.Optional or throw (Checked/Unchecked)exception

I need to create a method to find an employee by employee's name. There are three possible solution to implement this as below : Employee findEmployeeById(long empId) throws NoSuchEmployeeCheckedException; Optional findEmployeeById(long…
0
votes
1 answer

Spring batch continue job flow in case of unchecked exception

I send email in Spring Batch Tasklet. SMTP server is down so unchecked MailSendException exception occurred. Next step in transition is declared as (from email sending): FlowBuilder flowBuilder = new FlowBuilder("myFlow") …
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
0
votes
2 answers

How does one decide to create a checked excpetion or an unchecked exception

I want to know how does one know to create and throw a checked exception or an unchecked exception. For example I have a service which takes some data and validates it before using it. During validation a certain field did not meet the rules and I…
0
votes
3 answers

What does it mean by saying "It is impossible to recover from errors" in java?

Here says that it is impossible to recover from errors. I am not sure what does it mean because I can catch Error just like Exception. Eg: public static void main(String args[]) { while (true) { try { throw new…
0
votes
2 answers

Replacing generic exceptions with more specific exception types?

For a project I've been working on, we have some blocks that look like this: Class A: try { callSomeMethod(); } catch (Exception e) { throw new SomeCustomExceptionTypeForMetrics(""); } However, I was tasked with replacing all instances…
CustardBun
  • 3,457
  • 8
  • 39
  • 65
0
votes
1 answer

Java Performance concern in Exception Handling

I am aware of the Checked and Unchecked Exception in Java. In a multi-tiered environment, does unchecked Exception has a better performance over checked Exception?
SyntaX
  • 2,090
  • 17
  • 30
0
votes
1 answer

Java Checked vs Unchecked exception for validation service

I have a service that allow users to add dynamic content to a repository. So basically I have a generic Document class that contains a list of property for that specific object depending on what type of document the user is adding (eg. an invoice…
Nicola
  • 2,876
  • 2
  • 18
  • 26
0
votes
1 answer

Which unchecked exceptions to catch when dealing with networking (URLs, connections, ...)?

I'm working on webservices with Axis and among the checked exceptions that its methods declare I have: ServiceException, RemoteException and AxisFault (those depend, of course, on the specific method invoked, so these are not all the relevant…
watery
  • 5,026
  • 9
  • 52
  • 92
0
votes
3 answers

Override a method from an unchecked Exception class in Java

I am trying to override the getMessage() method in the NumberFormatException class in Java, which is an unchecked Exception. For some reason, I am unable to override it. I know it must be something really simple, but can't understand what I could be…
0
votes
1 answer

unchecked or unsafe operations even after specifying type

I get the following warning Note: com.......\BeerSelect.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. I have specified the type as well.. I would like to know the reason rather than using the…
0
votes
1 answer

How to avoid handling RunTimeException in Jersey

The most popular desicion for handling exceptions in rest service and return the error message to client - as i understand - is to catch WebApplicationException or MappableContainerException. But they are extending RuntimeExceprion (I don't…
-1
votes
1 answer

Which Exception get priority Checked or Unchecked ? and Why?

I written my own two customized Exception one is checked and other is unchecked when i'm executing my code is shows only checked Exception Why i'm not able to get unchecked Exception output?? class Test { public static void main(String…
Rohit Maurya
  • 730
  • 1
  • 9
  • 22