In the class description for the javafx.scene.control.Alert class there is a code example like this:
* <p><strong>Option 1: The 'traditional' approach</strong>
* <pre>{@code Optional<ButtonType> result = alert.showAndWait();
* if (result.get() == ButtonType.OK) {
* formatSystem();
* }}</pre>
If the user closes the alert dialog without clicking a button (for example, using the little red cross at the top right of the dialog window on Windows), the following exception is thrown:
java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135) ~[?:1.8.0_40-ea]
To avoid this, the check on the result would be better written as follows:
if (result.isPresent() && result.get() == ButtonType.OK) {
* <p><strong>Option 1: The 'traditional' approach</strong>
* <pre>{@code Optional<ButtonType> result = alert.showAndWait();
* if (result.get() == ButtonType.OK) {
* formatSystem();
* }}</pre>
If the user closes the alert dialog without clicking a button (for example, using the little red cross at the top right of the dialog window on Windows), the following exception is thrown:
java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135) ~[?:1.8.0_40-ea]
To avoid this, the check on the result would be better written as follows:
if (result.isPresent() && result.get() == ButtonType.OK) {