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
1
vote
2 answers

Get rid of a checked exception when using NIO2 API

Currently, I was loading a property file from the classpath using the following code with the help of Guava API: final URL fileURL = Resources.getResource("res.properties"); final File file = new File(fileURL.getFile()); I decided to give a try the…
jilt3d
  • 3,864
  • 8
  • 34
  • 41
1
vote
5 answers

How does java detects Checked Exceptions?

If i write things like this : public static void main(String[] args) { try { } catch (MalformedURLException e) { e.printStackTrace() }; } Java compiler shows compilation error at catch clause of MalformedURLException. If i…
mohit
  • 1,087
  • 1
  • 9
  • 18
0
votes
0 answers

Method reference of method throwing checked exception triggers compilation error at point method reference is named

I have a bunch of methods, with similar signatures, compatible with Function, they each declare throws InterruptedException, and I put them in a list and select one by its index and call its apply(). Except that I get a compiler error where the…
davidbak
  • 5,775
  • 3
  • 34
  • 50
0
votes
2 answers

Is there a way to detect the overflow-checking context in code?

I'm working on an importer for LitJson, to import float values from ints, and doubles, and if overflow-checking is enabled, I want to wrap a potential overflow exception in a JsonException with a bit more information about the failure. Right now my…
user3915050
0
votes
3 answers

Is it possible to pass on an exeption thrown during a stream operation?

Consider the following java code: public void write(FrameConsumer fc) throws FFmpegFrameRecorder.Exception{ frameStream.forEach(n -> fc.consume(n)); } In this case "frameStream" is a Stream of Objects that can be passed to…
0
votes
0 answers

Why Exceptions are categorized as Checked and unchecked?

I got one doubt regarding exception handling. We have checked and unchecked exceptions. Why they have given like that? irrespective checked or unchecked we have to handle the exception. Then i am unable to draw a line why that is given like…
0
votes
1 answer

Why doesn't Lombok.sneakyThrows throw a ClassCastException?

I am trying to understand how the @SneakyThrows annotation in Lombok actually works under the hood. From this SO answer, I can gather it uses the method Lombok.sneakyThrows() under the hood. The code for Lombok.sneakyThrows() is as follows: public…
ng.newbie
  • 2,807
  • 3
  • 23
  • 57
0
votes
1 answer

Groovy Spock: How do you pass in new Exception into when method without throwing error right away

I am trying to test a kafka error handler that takes in an Exception but as soon as I declare it in spock it actually throws it. def 'test example'() { when: service.emitError(new Exception('test exception')) then: // do some…
0
votes
1 answer

Program complies even when we do not handle the checked Exception thrown by Frame constructor?

As per Oracle Documentation https://docs.oracle.com/javase/7/docs/api/java/awt/Frame.html#Frame() Frame constructor throws HeadlessException - when GraphicsEnvironment.isHeadless() returns true But the program runs without handling the Exception…
0
votes
2 answers

Is it possible to throw an checked Exception implicitly, without any athrow instruction?

In Java, both checked exception and unchecked exception can be thrown explicitly, i.e, by a throw statement. Besides, unchecked exceptions like ArithmeticException and OutOfMemoryError can be triggered without any explicit throw statement like…
0
votes
1 answer

React fetch error/response catching not working

I built a signup page that needs to check whether an inputted email is already taken. When a duplicate email is taken, it gets stopped in the java spring api backend and returns a status of "400". (I've also tried using the spring annotation…
0
votes
0 answers

How to Anticipate Exceptions in C# When There Are No Checked Exceptions

In Java, calls to functions that can throw Exceptions need to anticipate them with either a try-catch or by adding a throws Exception to their function signature. My main use for them is in my top-calling code, where I only put try-catches in…
Floating Sunfish
  • 4,920
  • 5
  • 29
  • 48
0
votes
0 answers

What does it mean by propagating all exceptions in Java

I was told to propagate all exceptions. This sentence means active propagation such like : public void doSomething() throws SomeException{ try{ doSomethingThatCanThrowException(); } catch (SomeException e){ e.addContextInformation(�more…
Tonyukuk
  • 5,745
  • 7
  • 35
  • 63
0
votes
1 answer

Getting Exception In onGuildMessageReceivedEvent - Discord JDA

I am making a Discord JDA bot that can when a user sends the message: Prefix("$") + hastebin + their code, the bot will create a request to hastebin and paste their code, after that he will take the paste URL and print it to the console(I will send…
Tal Moshel
  • 232
  • 3
  • 18
0
votes
1 answer

Selective catch for a closeable resource

This is more of a syntax / structuring issue. I'm working with JDBC: Statement and ResultSet, which means SQLExceptions are being thrown everywhere. My code looks like this: private static final String MY_QUERY = "SELECT * FROM MY_TABLE"; public…
Jefferson
  • 379
  • 2
  • 4
  • 11