64 questions
1
vote
1
answer
110
views
What does AWS mean when they say that there are scalability issues with Checked Exceptions? [closed]
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 ...
9
votes
2
answers
587
views
Are there any differences between Checked and Unchecked Exceptions at Runtime?
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 ...
0
votes
0
answers
195
views
Spring Boot + Spring Security. How do I trigger a RequestRejectedException?
For a simple Spring Boot app with Spring Security, I want to trigger a RequestRejectedException and see it in my console output. I think I'm able to trigger a runtime expection of this type, but no ...
0
votes
0
answers
34
views
Why Exceptions are categorized as Checked and unchecked? [duplicate]
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 ...
0
votes
2
answers
188
views
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 ...
7
votes
2
answers
712
views
How do you judge whether to make an exception checked or unchecked?
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 ...
0
votes
0
answers
216
views
Catch a list of specific exception subtypes instead for unchecked exceptions [duplicate]
How do I determine what exception to use for unchecked exceptions?
For example
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {
LOG....
0
votes
1
answer
4k
views
XMLStreamException: ParseError at [row,col] when opening new stage (new window) [closed]
I'm trying to switch from a window to another one.
This is my code:
public class SelectTypeController implements Initializable {
@FXML
private Button buttonVai;
@FXML
private ComboBox&...
-4
votes
1
answer
954
views
Why can't Java Lambda throw an checked exception [closed]
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 ...
1
vote
3
answers
241
views
Why does throwing an unchecked exception removes the "missing return statement" error
I am very new at programming and the problem thus might seem very silly. The below mentioned method has a return type as an int array. When we don't throw any unchecked exception it throws an error ...
1
vote
0
answers
51
views
Throw Exception for Invalid JSONPath while parsing json for specific object key
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,
"...
0
votes
1
answer
2k
views
Check if an exception is a checked exception at runtime
Is this the correct way to check if an exception is a checked exception at runtime?
public boolean isChecked(final Throwable e) {
return !(RuntimeException.class.isAssignableFrom(e.getClass())
...
2
votes
1
answer
513
views
Should @Transactional method roll back in case of calling a private method which throws RuntimeException in Spring?
Should transaction rolled back here?
@Service
public class Serv {
@Transactional
public void method1() {
method2();
}
private void method2(){
throw new ...
3
votes
4
answers
2k
views
How to write an unchecked Throwable in java
I want to write a custom Throwable that is unchecked.
There are ways to trick the compiler at throw time (e.g. Utility class that re-throws a throwable as unchecked?), which I have implemented thus:
...
3
votes
2
answers
148
views
Unchecked cast behavior with and without assignment to variable
Why first line in main does not throw ClassCastException while the second does?
import java.util.function.Function;
class Scratch {
static <T> T getSomething(Function<Integer, T> ...
0
votes
0
answers
104
views
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-...
0
votes
0
answers
25
views
What does it mean by propagating all exceptions in Java [duplicate]
I was told to propagate all exceptions. This sentence means active propagation such like :
public void doSomething() throws SomeException{
try{
doSomethingThatCanThrowException();
} catch (...
0
votes
0
answers
293
views
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....
3
votes
2
answers
5k
views
How do I test expected Unchecked Exceptions in Kotlin?
I am trying to write a test in Kotlin that makes sure an unchecked exception is thrown in specific circumstances.
I am trying to use org.junit.jupiter.api.Assertions.assertThrows like this:
...
0
votes
1
answer
102
views
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 ...
0
votes
2
answers
1k
views
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 ...
2
votes
2
answers
1k
views
How to know if my code is using a checked or an unchecked exception?
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 ...
0
votes
1
answer
290
views
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 ...
-2
votes
1
answer
103
views
Is Exception checked or not in JAVA? [duplicate]
Consider the following code
public void myMethod1() {
try {
this.getClass().getMethod("myMethod").invoke(this);
} catch (Exception e) {
throw e;
}
}
public void ...
-1
votes
1
answer
212
views
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??
...
0
votes
1
answer
8k
views
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<Flow> ...
3
votes
1
answer
2k
views
Using Checked Exceptions vs Unchecked Exceptions with REST APIs
According to [1],
"When deciding on checked exceptions vs. unchecked exceptions, ask
yourself, What action can the client code take when the exception
occurs?. If the Client code cannot do ...
4
votes
2
answers
4k
views
Java 8 lambda catching exception
From the book Java 8 for the impatient by Cay Horstmann:
Didn’t you always hate it that you had to deal with checked
exceptions in a Runnable? Write a method uncheck that catches all
checked ...
6
votes
2
answers
6k
views
Is disabling Checked Exceptions in Java possible?
I was reading an article about checked and unchecked Exceptions in Java and found this article/link:
https://projectlombok.org/disableCheckedExceptions.html
According to the article it's just a hack ...
2
votes
3
answers
5k
views
Java unchecked conversion of arraylist
Can anybody tell me how to create an array-arraylist the right way ?!
.\File.java:5: warning: [unchecked] unchecked conversion
ArrayList<myObjectType> myParkingLotArray[] = new ...
0
votes
2
answers
684
views
How does one decide to create a checked excpetion or an unchecked exception [duplicate]
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 ...
0
votes
3
answers
2k
views
What does it mean by saying "It is impossible to recover from errors" in java? [duplicate]
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) {
...
8
votes
1
answer
3k
views
Why one should try throw unchecked exception over checked exception? [duplicate]
I've been told that I should consider throwing Unchecked exception over Checked exception in my code and not only that, but to extend the RuntimeException with my own one.
Now, I do understand the ...
5
votes
2
answers
136
views
Should I declare an unchecked exception?
I've got a method which invokes another method like this:
public void m1() {
m2(10);
}
public void m2(int v) {
if(v < 10)
throw new MyException();
}
public class MyException ...
1
vote
2
answers
5k
views
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("");
}
...
20
votes
2
answers
6k
views
Is there any easy way to see what exceptions a Kotlin function throws?
I mostly understand the potential issues with checked exceptions and why Kotlin omits them. However, the issue I am encountering is I can't find any foolproof way of clearly indicating to the caller ...
1
vote
2
answers
4k
views
Java method contains another method that throws exception
I have public method add(String) that calls private method inspectSequence(String) to check whether String valid or not.
This method returns array if passed String is valid, if it's invalid then ...
35
votes
3
answers
8k
views
Why is catching checked exceptions allowed for code that does not throw exceptions?
In Java, methods that throw checked exceptions (Exception or its subtypes - IOException, InterruptedException, etc) must declare throws statement:
public abstract int read() throws IOException;
...
0
votes
1
answer
157
views
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?
1
vote
4
answers
199
views
Customized Exception is checked or unchecked Exception?
Whether the Customized Exception is Checked or Unchecked Exception? How?
-3
votes
1
answer
2k
views
Reference of all checked / unchecked exceptions in the standard API [closed]
I'm trying to learn about exceptions in Java and, for educational purposes, it would be nice if I could get hold of a reference of all checked exceptions and all unchecked exceptions in the standard ...
1
vote
2
answers
2k
views
Custom Unchecked Exceptions
Okay guys I've been trying to figure this out for the past day or so. My homework assignment has me creating both Unchecked and Checked Exceptions. The checked exceptions I believe I get basically ...
1
vote
2
answers
123
views
Facing java.lang.StackOverflowError on throwing unchecked exception from constructor
I was trying out to run the below code sample but getting StackOverflow error. It seems to stuck up in the infinite loop. Can anybody help me out in knowing what's going on in here?
Please find below ...
5
votes
2
answers
1k
views
Always Use Checked Exceptions [closed]
I have been re-factoring some Java code lately... I have found that there were many RuntimeExceptions being thrown (i.e. unchecked exceptions). I have created my own checked exception and replaced ...
3
votes
2
answers
1k
views
How to convert / wrap Unchecked Exceptions into Checked Exceptions in Java?
Can Unchecked Exceptions be converted into Checked Exceptions in Java?
If yes, please suggest ways to convert/wrap an Unchecked Exception into a Checked Exception.
1
vote
1
answer
110
views
Why it is not recommended to handle unchecked exceptions by using try...catch blocks? Why only through some conditional checkings only?
Why it is not recommended to handle unchecked exceptions by using try...catch blocks?
Why we need to avoid them through some conditional checkings only?
0
votes
1
answer
1k
views
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 ...
5
votes
2
answers
914
views
How does JVM handles RuntimeException(s)
While creating custom exceptions, If we want to create a checked Exception we extend the Exception class and for unchecked exception we extend the RuntimeException class.
My question is, how JVM ...
15
votes
3
answers
2k
views
Is there an advantage to declaring that a method throws an unchecked exception?
If I have a method which throws an unchecked exception, e.g.:
void doSomething(int i) {
if (i < 0) throw new IllegalArgumentException("Too small");
// ...
}
is there any advantage to ...
0
votes
1
answer
185
views
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 ...