I'm working with javax.swing
to make an aplication which generates forms from XML Schema (using JAXFront library) and stores the data filled by the user them into XML documents.
I have put try-catch-finally blocks when I need it, but I have a little problem catching exceptions when the main thread ends (The AWT threads are still running).
I have two classes which do the main work and other classes which aren't important for the question:
Main class: It has the following structure. Initializes the application and runs the main frame
public class Main { public static void main(String[] args) { readArgs(); // An INI file with the app config Model model = initializeElements(args); // My model class try { MyFrame mfr = new MyFrame(title,model); mfr.visualize(); // Assembling view and setting visible } catch( Excepion e ) { doCleanUp(); System.exit(-1); } } }
Frame Class: Generates the view and listen events
public class MyFrame extends JFrame implements ActionListener,MenuListener { // Some attributes // Other mthods without importance /** * Compose the elements, add listeners and set visible the frame */ public void visualize() { generateFormPanel(); setListeners(); validate(); setVisible(true); } public MyFrame(String title, Modele model) { super(title); createElementsUsing(model); } public void actionPerformed(ActionEvent e) { // Code to manage events } }
Well, the problem is the following: When the visualize function is exectuted from the main method, the view is generated and showed. At that moment is when I lose the control of the exceptions catching. Then my question is if there are some way to catch the possible RuntimeExceptions throwed after this point.
I hope you understand my English and can answer the question.
Thanks in advance.