created an exception handler that creates a report and dispalys it to the user asking them to email it to twentycodes@gmail.com
This commit is contained in:
@@ -131,7 +131,8 @@ public class OrderDB {
|
||||
|| array.get(i).getCustomerName().toLowerCase(Locale.ENGLISH).contains(text.toLowerCase(Locale.ENGLISH)))
|
||||
list.add(array.get(i));
|
||||
|
||||
mListener.onProgressUpdate(i);
|
||||
if(mListener != null)
|
||||
mListener.onProgressUpdate(i);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -38,12 +38,16 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
||||
public static final boolean DEBUG = true;
|
||||
private JProgressBar mProgressBar;
|
||||
private String mCurrentFile;
|
||||
private UncaughtExceptionHandler mExceptionReport = new UncaughtExceptionHandler(this.getClass());
|
||||
|
||||
/**
|
||||
* Creates a new MainWindow
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public MainWindow() {
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler(mExceptionReport);
|
||||
|
||||
setTitle("Twenty Codes, LLC Order Database");
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
@@ -89,6 +93,7 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
||||
if(e.getSource() == mShowAllButton){
|
||||
new ShowAllDialog(db.toString());
|
||||
}
|
||||
|
||||
if (e.getSource() == mSearchButton) {
|
||||
new SearchDialog();
|
||||
}
|
||||
@@ -98,7 +103,7 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
||||
*/
|
||||
if(e.getSource() == mLoadFileButton){
|
||||
try {
|
||||
if(fc.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION)
|
||||
if(fc.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION){
|
||||
db.setOnProgressListerner(this);
|
||||
mProgressBar.setIndeterminate(true);
|
||||
mCurrentFile = fc.getSelectedFile().toString();
|
||||
@@ -117,6 +122,7 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
||||
});
|
||||
|
||||
pack();
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
|
||||
@@ -198,6 +198,9 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
||||
*/
|
||||
@Override
|
||||
public void onProgressUpdate(int progress) {
|
||||
if(MainWindow.DEBUG)
|
||||
System.out.println("search progress = "+ progress);
|
||||
|
||||
progress++;
|
||||
if(mProgressBar.isIndeterminate()) {
|
||||
mProgressBar.setIndeterminate(false);
|
||||
|
||||
@@ -25,20 +25,41 @@ public class ShowAllDialog extends JFrame implements ActionListener {
|
||||
/**
|
||||
* Creates a new ShowAllDialog
|
||||
*/
|
||||
public ShowAllDialog(String list){
|
||||
public ShowAllDialog(final String list){
|
||||
super();
|
||||
setTitle("Show All Accounts");
|
||||
setTitle("Show All Orders");
|
||||
|
||||
initialize(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ShowAllDialog
|
||||
*/
|
||||
public ShowAllDialog(String title, String body){
|
||||
super();
|
||||
setTitle(title);
|
||||
|
||||
initialize(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* initializes the dialog's components
|
||||
* @param body
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void initialize(String body) {
|
||||
JButton ok = new JButton("Ok");
|
||||
ok.addActionListener(this);
|
||||
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
|
||||
JTextArea results = new JTextArea();
|
||||
final JTextArea results = new JTextArea();
|
||||
scrollPane.setViewportView(results);
|
||||
|
||||
results.setEditable(false);
|
||||
results.setText(list);
|
||||
results.setText(body);
|
||||
|
||||
this.getContentPane().add(scrollPane, BorderLayout.CENTER);
|
||||
this.getContentPane().add(ok, BorderLayout.SOUTH);
|
||||
pack();
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* UncaughtExceptionHandler.java
|
||||
* @date Jan 6, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor.UI;
|
||||
|
||||
/**
|
||||
* An exception handler used to help report bugs in our applications
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class UncaughtExceptionHandler implements java.lang.Thread.UncaughtExceptionHandler {
|
||||
|
||||
private java.lang.Thread.UncaughtExceptionHandler mDefaultUEH;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Class mApp;
|
||||
|
||||
/**
|
||||
* Creates a new UncaughtExceptionHandler
|
||||
* @param c
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public UncaughtExceptionHandler(Class c) {
|
||||
mApp = c;
|
||||
mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread, java.lang.Throwable)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
new ShowAllDialog("We're Sorry....", getDebugReport(e));
|
||||
mDefaultUEH.uncaughtException(t,e);
|
||||
}
|
||||
|
||||
/**
|
||||
* generates a human readable report about the exception
|
||||
* @param e
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private String getDebugReport(Throwable e) {
|
||||
|
||||
StackTraceElement[] theStackTrace = e.getStackTrace();
|
||||
|
||||
StringBuffer report = new StringBuffer();
|
||||
|
||||
report.append("We're sorry, but there was an error with your application.\n" +
|
||||
" Please email this report to twentycodes@gmail.com to help make this application better. \n\n");
|
||||
|
||||
report.append("--------- Application ---------\n\n");
|
||||
|
||||
report.append(mApp.getName());
|
||||
|
||||
report.append(" generated the following exception:\n\n");
|
||||
|
||||
report.append(e.toString() + "\n\n");
|
||||
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
report.append("--------- Stack trace ---------\n\n");
|
||||
for (int i = 0; i < theStackTrace.length; i++) {
|
||||
report.append(" " + theStackTrace[i].toString() + "\n");
|
||||
}
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
// If the exception was thrown in a background thread inside
|
||||
// AsyncTask, then the actual exception can be found with getCause
|
||||
report.append("--------- Cause ---------------\n\n");
|
||||
Throwable cause = e.getCause();
|
||||
if (cause != null) {
|
||||
report.append(cause.toString() + "\n\n");
|
||||
theStackTrace = cause.getStackTrace();
|
||||
for (int i = 0; i < theStackTrace.length; i++) {
|
||||
report.append(" " + theStackTrace[i].toString() + "\n");
|
||||
}
|
||||
}
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
return report.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user