Lab 6: Exceptions
- Properly handle exceptions generated by an external class.
- Construct software which uses an FXML layout file.
ActionEventlisteners to detect events in text entry boxes.
- Interpret Javadoc to make effective use of unfamiliar classes.
TextInputDialogclasses into the handling of exceptions.
The web can be a wonderful place. We've all used a web browser to do useful things. But what is a web browser in reality? A web browser is a software application that downloads and renders files. Some files are text. Some files are binary. Some files have specific meaning such as images. But, all in all, the web just consists of a bunch of files that are accessed using a web protocol. In future classes you will learn more of the details of the web protocol. In this assignment you will build a system which will allow you to monitor material on the web.
You must create a desktop application using JavaFX that looks similar to the GUI shown below.
Specifically, this application will:
- Allow the user to enter a URL
- Allow the user to enter the length of time to wait for a response (timeout)
- Download the content of the specified URL
- Display the filesize
- Display the time it took to download the material
- Display which port the download is using
- Display the name of the host
The user should only be able to edit the URL and Timeout text fields.
Your solution must consist of a
Lab6 class that loads the FXML file
and launches the app, a
lab6.fxml file that describes the GUI layout,
Lab6Controller class that responds to the UI elements specified in the
FXML file. The
Lab6Controller class must have two methods named
setTimeout() that handle events caused by
pressing enter in the text fields or pressing the buttons.
Operation of the program begins with the user starting the program. The
program will start with
the default URL. The timeout will be set to the default value from the
WebsiteTester class. The size, port, download time, and
host entries will be blank, as well as the text area containing the text
from the website.
The user can then enter different text into the URL text field or enter a different value into the timeout text field. When the
user clicks on either button, an event handler will interact with the
WebsiteTester instance to produce the appropriate result. Pressing enter in the URL text field is equivalent to clicking the Analyze button, and pressing enter in the timeout text field is equivalent to clicking the Set button.
The sequence diagram below shows exactly what needs to be done to respond to each event.
If the timeout is invalid when an attempt is made to set the timeout, a
message dialog box is displayed indicating that an invalid timeout has been
entered by the user. When the message dialog closes, the text in the text field is
reverted to the timeout present in the
When the user clicks on Analyze, there is the potential for several errors to occur. First and foremost, there is the possibility that the URL is Malformed. If this is the case, a text entry indicating that the text in the box is invalid is displayed and the url text field is set to a blank entry.
If there is a socket timeout exception, a confirmation dialog is displayed indicating that the connection has timed out and asking if they would like to temporarily extend the timeout. If they choose to extend the timeout, then an input dialog is displayed allowing the user to select a temporary timeout. Once entered, the web request should be repeated using the desired temporary timeout.
If the host cannot be found, a message is displayed indicating that the user has attempted to reach a host which does not exist.
If a general IO error occurs, a message is shown indicating that there was a problem reading from the given file.
Sample Error Dialogs
Coding Standard Additions for Exceptions
The following additions to the coding standard must be observed when using expection handling.
- General catch blocks (e.g.,
(Exception e)) are avoided
- Catch blocks with auto-generated code (e.g.,
// TODO) are not left unmodified
- Exceptions are only caught when a sensible response is placed in catch blocks