-
Notifications
You must be signed in to change notification settings - Fork 44
Exceptions
RedDeer is made of a bunch of plugins and each of them is designed for specific needs. Some plugins are independent and some others are utilizing API from plug-ins bellow. So exception handing is important part what to expect when something goes wrong or if there is some unexpected state. RedDeer API can throw sever unchecked exceptions based on where (in which plugin) this exception was thrown.
You can see these unchecked exception mainly indicating that UI state of operation was not achieved on particular layer.
Reason for this quite obvious. User writing some test and wanting handle unexpected state doesn't need to do comprehensive research what exception might be thrown and also it simplifies process of writing additional API. And by using unchecked exception you have a freedom to ignore errors.
So if you're utilizing SWT layer code and want to handle errors you just need to wrap your call like this
try {
// SWT layer call
} catch (SWTLayerException e) {
// desired error handling
}
If you re-throw an exception don't forget to pass the cause exception.
catch (WaitTimeoutExpiredException cause) {
throw new SWTLayerException("Something bad happens",cause)
}
For cases when more descriptive exception text is needed SWTLayerException has possibility to add error message details using method addMessageDetails(String messageDetail)
Example bellow shows use case when Tree doesn't contains requested TreeItem and therefore SWTLayerException will be thrown. All current TreeItems labels of the Tree are added as Exception message details so when exception is displayed all current TreeItems will be also displayed
SWTLayerException exception = new SWTLayerException("Tree Item " + this
+ " has no Tree Item with text " + text);
exception.addMessageDetail("Tree Item " + this + " has these direct children:");
for (TreeItem treeItem : getItems(getParent(swtTreeItem).getSWTWidget())){
exception.addMessageDetail(" " + treeItem.getText());
}
For Eclipse layer EclipseLayerException can be thrown but just rarely. We suggest to use mainly SWTLayerException