// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

import netscape.javascript.*;

public class JSEx extends Applet implements ActionListener {
    public Button btn;
    public TextField txtf;
    public void init() {
        btn = new Button("Throw");
        btn.addActionListener(this);
        add(btn);
        txtf = new TextField("", 40);
        add(txtf);
        this.setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        try {
            JSObject window = JSObject.getWindow(this);
            window.eval("throwAnException()");
            txtf.setText("Everything OK");
        } catch (JSException ex) {
            // newer Java
            Exception ex2 = (Exception)ex.getWrappedException();
            txtf.setText(ex2.getClass().getName() + " " + ex2.getMessage());
        } catch (Exception ex) {
            // prehistoric MS Java
            txtf.setText(ex.getClass().getName() + " " + ex.getMessage());
        }
    }
}
