Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 4 years ago. Improve this ques…
Tag: exception
How to handle exceptions in Java Web Applications?
i would like to handle my exceptions in a way to warning the user about the errors that occured . What i know is something like: This is the best approach ? If not, what would you suggest ? Best regards, Valter Henrique. Answer An exception can be handled in different ways. In this case, it seems that the exc…
in which namespace / package to put exceptions?
What is the common or best practice to structure the location of your exception classes? Let’s say you have the packages/namespaces myproject.person (models and DAOs for persons) and myproject.order (models and DAOs for orders) and the exceptions PersonException and OrderException. Should I put the exce…
How to handle a static final field initializer that throws checked exception
I am facing a use case where I would like to declare a static finalfield with an initializer statement that is declared to throw a checked exception. Typically, it’d look like this: The issue I have here is that the ObjectName constructor may throw various checked exceptions, which I don’t care ab…
Java – find the first cause of an exception
I need to check if an exception is caused by some database problem. I receive an Exception and check if its cause contains the “ORA” string and return that (something like “ORA-00001”). The problem here is that the exception I receive is nested inside other exceptions, so if I don̵…
What are all the possible values for SQLException.getSQLState?
SQLException.getSQLState retrieves the SQLState for the SQLException object. What are all the possible values that can be returned by this method? Can I use the value to identify specific errors that occurred in the database (i.e. can this value tell me if it was a PK violation, or a unique constraint, or col…
How can I avoid ResultSet is closed exception in Java?
As soon as my code gets to my while(rs.next()) loop it produces the ResultSet is closed exception. What causes this exception and how can I correct for it? EDIT: I notice in my code that I am nesting while(rs.next()) loop with another (rs2.next()), both result sets coming from the same DB, is this an issue? A…
Should Exceptions be placed in a separate package?
I am taking on a project where all the Exceptions have been placed in a separate package com.myco.myproj.exceptions. Is this good practice? Answer I would expect the exceptions for a package to exist within that package. e.g. would contain pricing models and related exceptions. Anything else seems a bit count…
Best way to check whether a certain exception type was the cause (of a cause, etc …) in a nested exception?
I am writing some JUnit tests that verify that an exception of type MyCustomException is thrown. However, this exception is wrapped in other exceptions a number of times, e.g. in an InvocationTargetException, which in turn is wrapped in a RuntimeException. What’s the best way to determine whether MyCust…
Why is a ConcurrentModificationException thrown and how to debug it
I am using a Collection (a HashMap used indirectly by the JPA, it so happens), but apparently randomly the code throws a ConcurrentModificationException. What is causing it and how do I fix this problem? By using some synchronization, perhaps? Here is the full stack-trace: Answer This is not a synchronization…