/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. import java.awt.event.* ; 

2. import java.awt.* ; 

3. import java.applet.*; 

4.  

5. public class Exceptional 

6.     extends Applet 

7.     implements ActionListener 

8.

9.   void check ( String user ) 

10.         throws UnknownUserException 

11.   { 

12.     user = user.trim() ; 

13.  

14.     if (  ! user.equals( "HARDYOL"

15.         && ! user.equals( "LAURELST" )  ) 

16.       throw new UnknownUserException( ) ; 

17.  

18.     ta.append ( user + " has been approved\n" ); 

19.   } 

20.  

21.   public void actionPerformed( ActionEvent ev ) 

22.   { 

23.     String strusr ; 

24.     strusr = tf.getText() ; 

25.     ta.setText(""); 

26.     try 

27.     { 

28.       check ( strusr ) ; 

29.       ta.append ( "Y O U  M A Y  P A S S\n" ); 

30.       setBackground ( Color.green ) ; 

31.     } 

32.     catch ( UnknownUserException  uuex ) 

33.     { 

34.       ta.append ( "No admission for " + strusr + "\n" ); 

35.       ta.append ( "Exception as String : " + uuex + "\n" ); 

36.       setBackground ( Color.red ) ; 

37.       Toolkit.getDefaultToolkit().beep(); 

38. //      uuex.printStackTrace ( System.out ) ; 

39.     } 

40.     tf.requestFocus() ; 

41.   } 

42.  

43.   public Exceptional () 

44.   { 

45.     ta = new TextArea ( 6, 60 ) ; 

46.     tf = new TextField ( 30 ) ; 

47.  

48.     btEnter = new Button ( "ENTER" ) ; 

49.   } 

50.  

51.   public void init() 

52.   { 

53.     btEnter.addActionListener ( this ) ; 

54.     tf.addActionListener ( this ) ; 

55.  

56.     ta.setEditable ( false ) ; 

57.  

58.     add ( tf ) ; 

59.     add ( btEnter ) ; 

60.     add ( ta ) ; 

61.  

62.     validate () ; 

63.     tf.requestFocus (); 

64.   } 

65.   TextArea ta ; 

66.   TextField tf ; 

67.   Button btEnter ; 

68.

69. ///////  UnknownUserException.java  ///////// 

70. public class UnknownUserException 

71.     extends java.lang.Exception 

72.

73.   public  UnknownUserException ( ) 

74.   { 

75.     super ( "- user not known -" ) ; 

76.   } 

77.

78. //////  Disclosure.java  ////////// 

79.   void dooWit( ) 

80.   { 

81.     try

82.     otherMeth( ) ; 

83.     } 

84.     catch ( NumberFormatException nfex ) 

85.     {...} 

86.   } 

87.   void otherMeth( ) 

88.     throws NumberFormatException 

89.   { 

90.     Integer.parseInt ( str ) ; 

91.     ... 

92.   } 

93.