Throwing Run time exception in Echo3

While creating any application the developers must be
aware with the fact that there are lots of cases where the user may perform
wrong inputs and wrong button pressing and such activities. So to create a more user-friendly
application its necessary that the developers handle the exception when they are
thrown to avoid of making application halted while application is in
process. In Echo3 also, a user can throw runtime exceptions. Here is an example
of application that throws a RuntimeException as described below.
In the following application we have created a button
which will throw a RuntimeException when user presses that button.Here is the
full example source code in detail for application.
ExceptionServlet.java
package echo;
import nextapp.echo.app.ApplicationInstance;
import nextapp.echo.webcontainer.WebContainerServlet;
public class ExceptionServlet extends WebContainerServlet {
public ApplicationInstance newApplicationInstance() {
return new ExceptionApp();
}
}
|
ExceptionApp.java
package echo;
import nextapp.echo.app.ApplicationInstance;
import nextapp.echo.app.ContentPane;
import nextapp.echo.app.Label;
import nextapp.echo.app.Window;
import nextapp.echo.app.*;
import nextapp.echo.app.event.ActionListener;
import nextapp.echo.app.event.ActionEvent;
public class ExceptionApp extends ApplicationInstance {
public Window init() {
Window window = new Window();
window.setTitle("Exception Example");
ContentPane contentPane = new ContentPane();
Button thr=new Button("Throw Run Time Exception");
thr.setBorder(new Border(2,Color.BLUE,Border.STYLE_SOLID));
contentPane.add(thr);
thr.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
throw new RuntimeException("Application has thrown RuntimeException.");
}
});
window.setContent(contentPane);
return window;
}
}
|
Output:

Download Project Source Code