ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/error.htm

94 lines
5.5 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Error events" />
<meta name="abstract" content="In most cases, the IBM Toolbox for Java GUI components fire error events instead of throw exceptions." />
<meta name="description" content="In most cases, the IBM Toolbox for Java GUI components fire error events instead of throw exceptions." />
<meta name="DC.Relation" scheme="URI" content="gui.htm#gui" />
<meta name="DC.Relation" scheme="URI" content="except.htm" />
<meta name="DC.Relation" scheme="URI" content="progtips.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="error" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Error events</title>
</head>
<body id="error"><a name="error"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Error events</h1>
<div><p>In most cases, the IBM<sup>®</sup> Toolbox for Java™ GUI components fire error events instead
of throw exceptions.</p>
<div class="section"><p>An error event is a wrapper around an exception that is thrown
by an internal component.</p>
<p>You can provide an error listener that handles
all error events that are fired by a particular graphical user interface component.
Whenever an exception is thrown, the listener is called, and it can provide
appropriate error reporting. By default, no action takes place when error
events are fired.</p>
<p>The IBM Toolbox for Java provides a graphical user interface
component called <a href="javadoc/com/ibm/as400/vaccess/ErrorDialogAdapter.html#NAVBAR_TOP"> ErrorDialogAdapter</a>, which automatically displays a dialog
to the user whenever an error event is fired.</p>
</div>
<div class="section"><h4 class="sectiontitle">Examples</h4><p>The following examples show how you can
handle errors and define a simple error listener.</p>
<p id="error__errex1"><a name="error__errex1"><!-- --></a><strong>Example:
Handling error events by displaying a dialog</strong></p>
<p>The following example
shows how you can handle error events by displaying a dialog:</p>
<pre> // All the setup work to lay out a graphical user interface component
// is done. Now add an ErrorDialogAdapter as a listener to the component.
// This will report all error events fired by that component through
// displaying a dialog.
ErrorDialogAdapter errorHandler = new ErrorDialogAdapter (parentFrame);
component.addErrorListener (errorHandler);</pre>
<p id="error__errex2"><a name="error__errex2"><!-- --></a><strong>Example:
Defining an error listener</strong></p>
<p>You can write a custom error listener
to handle errors in a different way. Use the <a href="javadoc/com/ibm/as400/vaccess/ErrorListener.html#NAVBAR_TOP"> ErrorListener</a> interface to accomplish this.</p>
<p>The
following example shows how to define an simple error listener that only prints
errors to System.out:</p>
<pre> class MyErrorHandler
implements ErrorListener
{
// This method is invoked whenever an error event is fired.
public void errorOccurred(ErrorEvent event)
{
Exception e = event.getException ();
System.out.println ("Error: " + e.getMessage ());
}
} </pre>
<p id="error__errex3"><a name="error__errex3"><!-- --></a><strong>Example: Handling error events by using
an error listener</strong></p>
<p>The following example shows how to handle error
events for a graphical user interface component using this customized handler:</p>
<pre> MyErrorHandler errorHandler = new MyErrorHandler ();
component.addErrorListener (errorHandler);</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="progtips.htm" title="This section features a variety of tips that can help you use IBM Toolbox for Java.">Tips for programming</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="gui.htm#gui" title="The Vaccess package and its classes have been deprecated. You are advised to use the Access package in combination with Java Swing instead.">Vaccess classes</a></div>
<div><a href="except.htm" title="The IBM Toolbox for Java access classes throw exceptions when device errors, physical limitations, programming errors, or user input errors occur. The exception classes are based upon the type of error that occurs instead of the location where the error originates.">Exceptions</a></div>
</div>
</div>
</body>
</html>