Skip to main content
Filter by
Sorted by
Tagged with
3 votes
1 answer
40 views

I am trying to search for elements on a webpage and have used various methods, including text and XPath. It seems that the timeout option does not work the way I expected, and no exception is raised ...
Shankboy's user avatar
1 vote
1 answer
109 views

I am upgrading AWS' Java SDK from 1.x to 2.x. In 2.x, it seems that most exceptional cases are modeled with Unchecked Exceptions, as opposed to Checked Exceptions like it was in 1.x. When trying to ...
davidalayachew's user avatar
9 votes
2 answers
587 views

Checked Exceptions are powerful because they allow you to force the use-site to deal with an exceptional case. If the use-site does not handle an exceptional case (or publically announce that they are ...
davidalayachew's user avatar
4 votes
1 answer
95 views

I am compiling this class: public class Test { // No throws clause here public static void main(String[] args) { doThrow(new SQLException()); } static void doThrow(Exception ...
sparsh goyal's user avatar
1 vote
0 answers
163 views

how can I describe the exceptions thrown from callable in phpDoc? For example I have: /** * @param callable(int): bool */ function (callable $foo, int $number): ?bool { try { return $foo(...
Александр Рязанов's user avatar
-1 votes
1 answer
222 views

I was going through some Exception Handling concepts in Java and came across the concept of final rethrow. I read the following article- https://baptiste-wicht.com/posts/2010/05/better-exception-...
ayush's user avatar
  • 696
0 votes
0 answers
23 views

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(). ...
davidbak's user avatar
  • 6,098
1 vote
0 answers
44 views

Why is explicit division By zero not considered as compile time exception in JAVA ? Example : int x =9; int y = (int)x/0; Shouldnt compiler notify me about it ? I tried running the same and finding ...
Rohit Rohra's user avatar
2 votes
0 answers
49 views

JLS 11.2.3 says that it is a compile time error if a method body can throw a checked exception and it does not declare the class (or a parent class) in its throws clause. In the following code, ...
MattDs17's user avatar
  • 421
0 votes
2 answers
155 views

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 ...
user avatar
0 votes
3 answers
80 views

Consider the following java code: public void write(FrameConsumer fc) throws FFmpegFrameRecorder.Exception{ frameStream.forEach(n -> fc.consume(n)); } In this case "...
CopperCableIsolator's user avatar
0 votes
0 answers
34 views

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 ...
Praveen kumar's user avatar
6 votes
1 answer
5k views

New Java programmers frequently encounter errors phrased like this: "error: unreported exception <XXX>; must be caught or declared to be thrown" where XXX is the name of some ...
Stephen C's user avatar
  • 723k
2 votes
1 answer
85 views

Problem I have a class with two constructors. One of them (A) throws a checked exception, and the other one (B) calls the first one. // Constructor A public ArrayValue(DataType rules, Value... content)...
xtay2's user avatar
  • 983
1 vote
1 answer
348 views

This is the block of code inside the boolean method that I want to check if there are any empty or null fields. It returns true if none of them are. If they are, it throws a custom exception for each ...
nikosidij's user avatar
-1 votes
3 answers
2k views

I am new to Java, I read that checked exception get raised during compile time only i.e. program will not compile successfully if there is a checked exception which is not handled or thrown. If ...
wholesome's user avatar
  • 102
2 votes
0 answers
97 views

I am writing a library in which I use checked exceptions internally as it helps to make sure that all paths handle certain exceptional cases. However, I don't want to burden the users of my library ...
john16384's user avatar
  • 8,088
1 vote
1 answer
2k views

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 ...
ng.newbie's user avatar
  • 3,332
0 votes
1 answer
1k views

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('...
James Nickelby's user avatar
1 vote
0 answers
22 views

Is there a way to declare a method in a generic type that wraps another method for another type and declares the same thrown exceptions? The most common example I can think of for this would be ...
Sir Intellegence-BrainStormexe's user avatar
0 votes
1 answer
88 views

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 ...
Vinayak Bansal's user avatar
-1 votes
2 answers
70 views

I'm struggling figuring out something about checked Exception in Java. What I've learned (I may be wrong) is that if you throw a checked Exception you have two options. you have to catch it with try ...
Michele Bianchi's user avatar
0 votes
2 answers
182 views

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 ...
cbcwestwolf's user avatar
-1 votes
2 answers
263 views

The following method will warn about IOException if called in Java code but will simply ignore any warning in Kotlin because IOException is a checked exception. ParcelFileDescriptor.open(file, ...
Farid's user avatar
  • 2,613
7 votes
2 answers
712 views

I was reading about checked vs unchecked exceptions in Java and when to use each: Here's the bottom line: If a client can reasonably be expected to recover from an exception, make it a checked ...
temporary_user_name's user avatar
0 votes
1 answer
2k views

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&...
ida nicole herbert's user avatar
38 votes
7 answers
59k views

I was playing with the Lombok library in Java and found an annotation called @SneakyThrows. As the documentation states: @SneakyThrows fakes out the compiler. In other words, Lombok doesn't wrap or ...
Shivanshu's user avatar
  • 914
2 votes
2 answers
968 views

For unchecked (runtime) exceptions it is understandable. They are literally propagated through stack. But why is it said that checked exceptions are not? Yes, we have to declare (throws) or handle ...
Stefan's user avatar
  • 1,069
-4 votes
1 answer
953 views

I'm learning Java and am a bit confused, why Lambda Expressions can't throw checked exceptions. Anyone has an understandable explanation for this? I read through this post: Java 8 Lambda function that ...
hallo545401's user avatar
1 vote
0 answers
49 views

I am trying to read a list from a specific object key cars Input is jsonString: { "id": 600000, "name": "Ayman", "cars": [ { "manufacturer": "Volvo", "economy" : 65, "...
Ayman Arif's user avatar
  • 1,735
33 votes
1 answer
9k views

And how do we handle this when we are calling a method in Java which throws exceptions ? my code is in kotlin and I am using a 3rd party library which is written in java. I call a method of this ...
user avatar
25 votes
3 answers
57k views

I have a method which I am trying to test public List<User> getUsers(String state) { LOG.debug("Executing getUsers"); LOG.info("Fetching users from " + state); List<...
sk17261205's user avatar
0 votes
0 answers
104 views

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-...
Floating Sunfish's user avatar
22 votes
4 answers
5k views

I am wondering why the java compiler allows throws in the method declaration when the method will never throw the Exception. Because "throws" is a way of handling the exception (telling the caller to ...
PsyAp's user avatar
  • 323
0 votes
0 answers
25 views

I was told to propagate all exceptions. This sentence means active propagation such like : public void doSomething() throws SomeException{ try{ doSomethingThatCanThrowException(); } catch (...
Tonyukuk's user avatar
  • 6,295
0 votes
1 answer
648 views

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 ...
Tal Moshel's user avatar
-3 votes
1 answer
3k views

the output is not a complete one, and neither are the exceptions handled. Please help. public class ATM { private String message; public ATM(String m) { if (m == null || m.trim()....
Shweta Nichani's user avatar
2 votes
1 answer
3k views

I am trying to throw an exception inside lambda but it keeps giving me an error saying that Unhandled IOException. private <T> T getResponse(final RestURI query, final Class<T> ...
user3407267's user avatar
  • 1,634
1 vote
0 answers
2k views

I used a static method supplyAsync() to get a CompletableFuture, and call its whenComplete() method to deal with the result and exception. whenComplete() accepts a BiConsumer as parameter, and ...
lulijun's user avatar
  • 593
0 votes
1 answer
48 views

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 ...
Jefferson's user avatar
  • 399
24 votes
3 answers
2k views

I'm just curious, is there any other languages besides Java that uses checked exceptions ? I did try to find information about this but couldn't find any answers.
Christiaan's user avatar
3 votes
2 answers
1k views

Have a look at the following snippet that tries to convert a list of strings into a list of class objects: public static List<Class<?>> f1(String... strings) { return Stream....
Angle.Bracket's user avatar
0 votes
3 answers
816 views

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 ...
ChrisLifts's user avatar
2 votes
2 answers
1k views

Are there any keywords or special syntax of code that if I look at it, I'll know that here unchecked exception is being used or a checked exception is being used? From reading previous posts that ...
Viola's user avatar
  • 43
2 votes
2 answers
235 views

elm's claim of zero-runtime-exceptions is one of its major selling point (see official website), But if you stop to think about it, nothing stops you from dividing by zero or running out of memory. ...
Uri Goren's user avatar
  • 13.8k
2 votes
1 answer
518 views

I have encountered that I must catch all checked exceptions inside stream expresions. I have read very popular topic: How can I throw CHECKED exceptions from inside Java 8 streams? And there is ...
gstackoverflow's user avatar
1 vote
2 answers
2k views

I am puzzled about creating checked exception class in java. Many article says custom exception can be created by class MyException extends Exception { //constructor defined } Since ...
Ankit's user avatar
  • 2,276
0 votes
1 answer
289 views

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 ...
jason zhang's user avatar
2 votes
1 answer
317 views

I notice that methods in some sophisticated libraries, including the standard JDK, tend to throws upcasting exception. At first I found this phenomenon in the source code of Apache POI, later see it ...
SedriX's user avatar
  • 552
-2 votes
1 answer
103 views

Consider the following code public void myMethod1() { try { this.getClass().getMethod("myMethod").invoke(this); } catch (Exception e) { throw e; } } public void ...
user1589188's user avatar
  • 5,778