Are there any guidelines on exception propagation in Java?
When do you add an exception to the method signature?
For example: if an exception is only thrown when an essential program resource is missing, and can only be handled at the top level, do I propagate it through all methods using this exception through all the methods using the erring method?
Are there any good practices? Any bad pra...
I am not as familiar with Java's exception packages as with those of .NET. I'm in a situation where, if programming in C#, I would throw a System.InvalidOperationException.
Before creating my own java.lang.RuntimeException subclass, I need to know if there is a similar exception type I should throw in Java.
The exact scenario is:
My class is a value object that provides an int intValue() me...
Description for java.lang.IllegalStateException from the Java docs:
Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.
Is there an equivalent for IllegalStateException in the .NET-Framework?
I want to ask why we don't have to add try-catch block to a RuntimeException while we should do that with other exceptions?
I mean like :
public class Main {
public static void main(String[] args) {
throw new RuntimeException();
}
}
Edit :
when I say : throw new RuntimeException(); it is so clear that there is an exception will happen ,so why the compiler doesn't forbid that ?
I'm converting some C# code to Java and I need to include an exception that is similar to C#'s InvalidOperationException. Does such a thing exist? Also is there a list of equivalent exception types in the two languages? Thanks.
I think in my particular case IllegalStateException is most appropriate. Thanks for all the responses.
Take this method
/**
* @return List of group IDs the person belongs to
*
*/
public List<String> getGroups() {
if (this.getId().equals("")) return null;
}
I would like to throw exception instead returning null, what's the exception to throw when an important parameter/dependency has not been set?
I want to throw a runtime exception in case my class invariants are invalidated. Since this is a programming error (similar to a NullPointerException), clients should not catch that exception.
Should the exception class be declared private or public (or something else)?
class Foo
{
// ...
private static class InvariantsViolated
{
// ...
}
}
Are there any guidelines ...
We are using OC4J 10.1.3.5 and ADF. I have a popup form and when closing we got error below. I wonder what am I missing and how can I resolve it?
Jun 15, 2010 8:26:49 AM com.sun.faces.lifecycle.ApplyRequestValuesPhase execute
SEVERE: java.lang.IllegalStateException: popView(): No view has been pushed.
javax.faces.el.EvaluationException: java.lang.IllegalStateException: popView(): No view has...
I have a JSF form over a JSF 1.2 Session Scope Bean.
I have a "Reset" button which invalidates the session.
I tried to use cookies to remember a session number (Not JSF session but my private session number) between sessions but I failed.
My question - Where is the correct place (Some listener? Bean Constructor?) to initialize, retrieve and store the cookie.
Looking for the best method to do ...
Here is the basic code i'm trying to make work:
Field fields[] = SalesLetter.class.getDeclaredFields();
String fieldName;
for (int j = 0, m = fields.length; j < m; j++) {
fieldName = fields[j].getName(); //example fieldname [[headline]]
templateHTML = templateHTML.replace(fieldName, Letter.fieldName());
}
I believe I'm going about it wrong by trying to getDeclaredFields (wh...
I'm a moderate fan of using Exception subtypes to help describe the problem that caused the exception. For instance, let's say that I'm writing a method that does not allow int values greater than 100 to be passed in as arguments. I'll often start the method with a condition to guard against this, and throw an exception if it occurs. I'll probably throw a System.Argument exception (with an appr...