EMMA Coverage Report (generated Mon Mar 20 21:34:30 PST 2006)
[all classes][com.moesol.util]

COVERAGE SUMMARY FOR SOURCE FILE [UnhandledExceptionDialog.java]

nameclass, %method, %block, %line, %
UnhandledExceptionDialog.java0%   (0/2)0%   (0/8)0%   (0/133)0%   (0/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UnhandledExceptionDialog0%   (0/1)0%   (0/6)0%   (0/123)0%   (0/30)
<static initializer> 0%   (0/1)0%   (0/15)0%   (0/1)
UnhandledExceptionDialog (): void 0%   (0/1)0%   (0/3)0%   (0/1)
safeShowException (Throwable): void 0%   (0/1)0%   (0/29)0%   (0/5)
showException (Throwable): void 0%   (0/1)0%   (0/15)0%   (0/6)
showExceptionDetails (Throwable): void 0%   (0/1)0%   (0/55)0%   (0/16)
showExceptionLater (Throwable): void 0%   (0/1)0%   (0/6)0%   (0/2)
     
class UnhandledExceptionDialog$10%   (0/1)0%   (0/2)0%   (0/10)0%   (0/3)
UnhandledExceptionDialog$1 (Throwable): void 0%   (0/1)0%   (0/6)0%   (0/1)
run (): void 0%   (0/1)0%   (0/4)0%   (0/2)

1/*
2 * $Id: UnhandledExceptionDialog.java,v 1.2 2005/12/03 07:52:34 hastings Exp $
3 *
4 * (c) Copyright, Moebius Solutions, Inc., 2004
5 *
6 *                       All Rights Reserved
7 *
8 * This material may be reproduced by or for the U. S. Government
9 * pursuant to the copyright license under the clause at
10 * DFARS 252.227-7014 (OCT 2001).
11 */
12 
13package com.moesol.util;
14 
15import java.awt.EventQueue;
16import java.io.PrintWriter;
17import java.io.StringWriter;
18 
19import javax.swing.JDialog;
20import javax.swing.JEditorPane;
21import javax.swing.JOptionPane;
22import javax.swing.JScrollPane;
23 
24/**
25 * @author robert
26 */
27public class UnhandledExceptionDialog {
28        /*
29         * Posts the exception dialog from the awt thread.
30         */
31    public static void showExceptionLater(final Throwable t) {
32        EventQueue.invokeLater(new Runnable() {
33            public void run() {
34                showException(t);
35            }
36        });
37    }
38    /*
39     * Shows the exception in an unhandled exception dialog.
40     * asserts that it is called from the awt thread.
41     */
42    public static void showException(Throwable t) {
43            assert(EventQueue.isDispatchThread());
44        try {
45            safeShowException(t);
46        } catch (Throwable e) {
47            // Since we are in the process or reporting
48            // an exception generating another exception
49            // now could cause an infinite loop of exceptions!
50            e.printStackTrace();
51        }
52    }
53    private static void safeShowException(Throwable t) {
54        Object[] options = { "OK", "Details..." };
55        int selectedOption =
56            JOptionPane.showOptionDialog(
57                null,
58                t,
59                "Unhandled Exception",
60                JOptionPane.DEFAULT_OPTION,
61                JOptionPane.ERROR_MESSAGE,
62                null,
63                options,
64                options[0]);
65        if (selectedOption == 1) {
66            showExceptionDetails(t);
67        }
68    }
69    private static void showExceptionDetails(Throwable t) {
70        // create
71        JDialog details_dlg = new JDialog();
72        JEditorPane msg_pane = new JEditorPane();
73        JScrollPane scroll_pane = new JScrollPane();
74 
75        // connect            
76        scroll_pane.getViewport().add(msg_pane);
77        details_dlg.getContentPane().add(scroll_pane);
78 
79        // configure
80        details_dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
81        StringWriter sw = new StringWriter();
82        PrintWriter pw = new PrintWriter(sw);
83        t.printStackTrace(pw);
84        pw.flush();
85        //msg_pane.setContentType("text/html");
86        msg_pane.setText(sw.toString());
87 
88        // show                
89        details_dlg.pack();
90        details_dlg.setSize(640, 480);
91        details_dlg.setVisible(true);
92        details_dlg.toFront();
93    }
94}

[all classes][com.moesol.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov