I have a TableModel that may throw an exception on its setValueAt
method if user enters an invalid value:
public class MyTableModel extends AbstractTableModel {
public void setValueAt(Object value, int rowIndex, int columnIndex) {
String valueStr = (String) value;
// some basic failure state
if(valueStr.length()>5) {
throw new ValidationException("Value should have up to 5 characters");
}
this.currentValue = valueStr;
}
}
Question is: how can another class catch this exception? It may show a popup message, or update a status bar, or paint the cell red. Whatever I chose to do, I don't think the TableModel
should be doing that.
First alternative is to use a
Thread.setDefaultUncaughtExceptionHandler
:but I am not sure if there's a more proper way to handle this situation, like some sort of exception listener.