Questions tagged [checked-exceptions]

The exceptions that 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.

The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.

The class Exception and any subclasses that are not also subclasses of RuntimeException are checked exceptions. Checked exceptions 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/Exception.html

145 questions
0
votes
3 answers

Comparing checked and unchecked exceptions (Performance, Benchmarks) in Java

Are there scenarios where you could argue that when an exception is created that both a checked exception and an unchecked exception can be used? Then the speed and performance can be measured against each other
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
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
1 answer

How do I deal with checked exceptions in lambda?

I have the following code snippet. package web_xtra_klasa.utils; import java.util.Arrays; import java.util.Properties; import java.util.function.Function; import javax.mail.Message; import javax.mail.MessagingException; import…
Jagger
  • 10,350
  • 9
  • 51
  • 93
0
votes
2 answers

Chaining exceptions, catching exceptions to throw new ones

Imagine the following code as a part of some program (java): function z(){ try{ //some code here, that might throw exceptions. }catch (SomeException | SomeOtherException e){ //some exception handling here. } function y(){ z(); } function…
Mavoor
  • 1
0
votes
2 answers

Interfaces and exceptions

I was reading about Interfaces on tutorialspoint, and came across the following: "Checked exceptions should not be declared on implementation methods other than the ones declared by the interface method or subclasses of those declared by the…
user3055593
  • 69
  • 1
  • 8
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

Throw checked Exception from static block

i want to throw checked exception from a static block, when i tried that the following compilation error arises: error: unreported exception Exception; must be caught or declared to be thrown my static code block is as…
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
0
votes
1 answer

Should user input cause checked exceptions?

I have an operation/method that performs an insert to a database. It takes several fields and for various reasons that operation could fail because one or more of the inputs was not unique or because they conflict with some internal records that…
Usman Mutawakil
  • 4,993
  • 9
  • 43
  • 80
0
votes
1 answer

Issue with Exception type handling when not throwing them - wanting a more generic version of multi-catch

Sorry for the TL;DR, but I feel like it needs some explanation or it will be misunderstood. I have a method that makes a call to (generally external) code which I expect to sometimes throw a RuntimeException, and uses futures which can throw…
m24p
  • 664
  • 4
  • 12
0
votes
2 answers

lazy and efficient approach to checked exceptions

I'm writing small java networking programs for school; obviously RTFM is de rigueur, but in developing skeleton code is it efficient (it's obviously lazy) to just run it by the compiler to see if I've forgotten some checked exception (rather than:…
0
votes
1 answer

JPA : Checked exception to verify Database connection

I use JPA, with datasource configured in a persistence.xml file. What is the exception that I must throw (Checked Exception) if the database name doesnt exist anymore after deploying the application or password wrong because it has been changed…
user3169231
  • 257
  • 3
  • 13
0
votes
1 answer

throws statement for handled exceptions -- Java

Suppose the following code: public static void somMethod() throws IOException { try { // some code that can throw an IOException and no other checked exceptions } catch (IOException e) { // some stuff here -- no exception thrown in this…
Roam
  • 4,831
  • 9
  • 43
  • 72
0
votes
1 answer

Using Anonymous thread for catching Exceptions

I asked around regarding catching checked exceptions in the context of a thread; the accepted answer was to use Callables and Futures. But I realized that I can simply wrap the "working" method with Anonymous thread and catch the exception as it…
yuris
  • 1,109
  • 4
  • 19
  • 33
0
votes
1 answer

Exception model in Java, C++, Python

Hey I am wondering how does Java exceptions model differ that in C++ and Python? I thought it was that only Java had checked exceptions, but from what I read Python also has checked exceptions? Any thoughts would be great, Thanks
user1974753
  • 1,359
  • 1
  • 18
  • 32
1 2 3
9
10