Setter error checking I have a class called Duration which has the attributes hours, mins, and secs. These attributes have to stay within acceptable ranges, so I implemented the following in their setters:

public void setHours(int newHours){
    if (newHours &gt;= 0){
        hours = newHours;
    }
    else{
         throw new RuntimeException("Invalid argument values");
    }
}


and so on for the other attributes.

Is there a better design pattern I could be using here? Is this an appropriate use of the RuntineException?
Input validation is a critical aspect of any reliable program. Your code is functional, but there are a few things to note.

First up, the RuntimeException is not a good error type to return, use an IllegalArgumentException instead (because it is an illegal argument). Note that IllegalArgumentException extends RuntimeException so it does not need to be explicitly checked/thrown.

Next, you should validate inputs before using the values - using a "Guard Clause". While your code technically does that, the logic looks like the validation is done after the hours are updated.

Finally, error messages should give the user/programmer an indication of what's needed to fix the problem. Your message should be more useful.

So, all things considered, I would do the code as:

private void setHours(int newHours) {
    if (newHours &lt; 0){
         throw new IllegalArgumentException("Input hours must be positive value: " + newHours);
    }
    hours = newHours;
}