How can I put all output error message into a String Variable ??

Dear Sir:
I have following code, When I run it and I press overflow radio button, It outputs following message:
Caught RuntimeException: java.lang.NullPointerException
java.lang.NullPointerException
     at ExceptionHandling.ExceptTest.actionPerformed(ExceptTest.java:72)
     at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
     at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
     at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
     at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:291)
     at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
     at java.awt.Component.processMouseEvent(Component.java:6038)
     at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
     at java.awt.Component.processEvent(Component.java:5803)
     at java.awt.Container.processEvent(Container.java:2058)
     at java.awt.Component.dispatchEventImpl(Component.java:4410)
     at java.awt.Container.dispatchEventImpl(Container.java:2116)
     at java.awt.Component.dispatchEvent(Component.java:4240)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
     at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
     at java.awt.Container.dispatchEventImpl(Container.java:2102)
     at java.awt.Window.dispatchEventImpl(Window.java:2429)
     at java.awt.Component.dispatchEvent(Component.java:4240)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)Caught RuntimeException: java.lang.NullPointerException
     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)I hope to catch all these error message into a String Variable such as StrErrorMsg, then I can use System.out.println(StrErrorMsg) to print it out or store somewhere, not only display at runtime,
How can I do this??
Thanks a lot,
See code below.
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileInputStream;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class ExceptTest extends JFrame implements ActionListener {
    private double[] a;
  private JRadioButton divideByZeroButton;
  private JRadioButton badCastButton;
  private JRadioButton arrayBoundsButton;
  private JRadioButton nullPointerButton;
  private JRadioButton negSqrtButton;
  private JRadioButton overflowButton;
  private JRadioButton noSuchFileButton;
  private JRadioButton throwUnknownButton;
  public ExceptTest() {
    JPanel p = new JPanel();
    ButtonGroup g = new ButtonGroup();
    p.setLayout(new GridLayout(8, 1));
    divideByZeroButton = addRadioButton("Divide by zero", g, p);
    badCastButton = addRadioButton("Bad cast", g, p);
    arrayBoundsButton = addRadioButton("Array bounds", g, p);
    nullPointerButton = addRadioButton("Null pointer", g, p);
    negSqrtButton = addRadioButton("sqrt(-1)", g, p);
    overflowButton = addRadioButton("Overflow", g, p);
    noSuchFileButton = addRadioButton("No such file", g, p);
    throwUnknownButton = addRadioButton("Throw unknown", g, p);
    getContentPane().add(p);
  private JRadioButton addRadioButton(String s, ButtonGroup g, JPanel p) {
    JRadioButton button = new JRadioButton(s, false);
    button.addActionListener(this);
    g.add(button);
    p.add(button);
    return button;
  public void actionPerformed(ActionEvent evt) {
    try {
      Object source = evt.getSource();
      if (source == divideByZeroButton) {
        a[1] = a[1] / a[1] - a[1];
      } else if (source == badCastButton) {
        Frame f = (Frame) evt.getSource();
      } else if (source == arrayBoundsButton) {
        a[1] = a[10];
      } else if (source == nullPointerButton) {
        Frame f = null;
        f.setSize(200, 200);
      } else if (source == negSqrtButton) {
        a[1] = Math.sqrt(-1);
      } else if (source == overflowButton) {
        a[1] = 1000 * 1000 * 1000 * 1000;
        int n = (int) a[1];
      } else if (source == noSuchFileButton) {
        FileInputStream is = new FileInputStream("Java Source and Support");
      } else if (source == throwUnknownButton) {
        throw new UnknownError();
    } catch (RuntimeException e) {
      System.out.println("Caught RuntimeException: " + e);
      e.printStackTrace();
      System.out.println("Caught RuntimeException: " + e);
    } catch (Exception e) {
      System.out.println("Caught Exception: " + e);
  public static void main(String[] args) {
    JFrame frame = new ExceptTest();
    frame.setSize(150, 200);
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
    frame.show();
}

yes, I update as follows,
but not looks good.
import java.io.*;
public class UncaughtLogger implements Thread.UncaughtExceptionHandler {
    private File file;
    private static String errorMessage;
    public UncaughtLogger(File file) {
        this.file = file;
        //Thread.setDefaultUncaughtExceptionHandler(this);
    public UncaughtLogger(String str) {
        this.errorMessage = str;
        Thread.setDefaultUncaughtExceptionHandler(this);
    //@Override()
    public void uncaughtException(Thread t, Throwable e){
        try {
            log(e);
        } catch (Throwable throwable) {
            System.err.println("error in logging:");
            throwable.printStackTrace();
    private void log(Throwable e) throws IOException {
        PrintWriter out = new PrintWriter(new FileWriter(file, true));
        try {
            e.printStackTrace(out);
        } finally {
            out.close();
    private static UncaughtLogger logger = new UncaughtLogger(new File("C:/temp/log.txt"));
    private static UncaughtLogger logger2 = new UncaughtLogger(errorMessage);
    public static void main(String[] args) {
            String s1 = "Hello World!";
            s1 = null;
            String s2 = s1.getClass().getName();
            System.out.println(s1);
            System.out.println(s2);
            System.out.println("errorMessage =" + errorMessage);
}

Similar Messages

  • I've got my email folders showing but how can i put back my email messages into the folders from time machine

    my mac has been restored & i can see my email folders but how do i put back the saved emails from my time macine i can locate n see them but cant restore them

    Csound1 wrote:
    Into one of the domain accounts, or a specific mailbox in a domain account, that's your choice but:
    Remember that you are moving mail over the internet, and you are uploading (slower). If the quantities are large you must use caution.
    1. Copy, don't move, in the event of a failure the original will still exist, delete it later.
    2. Limit copies to <500 emails
    3. Single copy operations are more reliable than multiple.
    Take your time.
    Thanks, but impractical. Many of the folders have more than 500 emails. Total is about 2 GB (which I have free on iCloud btw)
    I tried creating a folder "Archive" in my iCloud, then tried dragging one iMac folder into the new "iCloud > Archive" folder on my iMac. I got the error message:
         Some items could not be created:
         The IMAP command “CREATE” failed with server error: Invalid mailbox name.

  • How can I put ALL my music back into one folder? I have 3 external drives and my music is all over the place. I can't backup my music because it will not search for all my songs.HELPPPPPPPPPPPPPPPPP

    How do I move ALL my music in iTunes back to its original space on my desktop. I have music on my desktop, music on an external hard drive and some saved on a flash. I cannot backup my music because I cannot locate it. I have 4 separate music libraries (same songs) but don't know where to begin to get my music and libraries back in order. CAN SOMEONE SHOW ME THE WAY HOME?

    Hi there old45,
    You may find the information in the article below helpful.
    iTunes 11 for Windows: Change where your iTunes files are stored
    http://support.apple.com/kb/PH12365
    Consolidate your files in the iTunes folder
    You can consolidate all the files in your library in the iTunes folder—for example, to make it easier to move your library to a new computer.
    Choose File > Library > Organize Library.
    Select “Consolidate files.”Files remain in their original locations, and copies are placed in the iTunes folder.
    To create folders (Music, Movies, TV Shows, Podcasts, Audiobooks, and so on) inside your iTunes folder, and place all your imported media files in the appropriate folders, select “Reorganize files in the folder ‘iTunes Media.’”
    Locate your iTunes files
    Do either of the following:
    Find out where a file is stored: Select the item in iTunes, and choose File > Get Info. The path to the file is shown at the bottom of the Summary pane (next to Where).
    Show the file in Windows Explorer: Select the song, and choose File > Show in Explorer.
    -Griff W.

  • How to Inscribe all the error messages into a single package ??

    Hi,
    I want to Inscribe all the error messages into a single package., and call the concern package from the exception block in every sp by passing the error code to that package, which will return the Concern error message to the calling Sp.,
    Can any one help me out how to accomplish this ., ?
    regards
    Raja

    I want to Inscribe all the error messages into a single package., Why do you want to inscribe all the messages in a package?
    I would suggest you to store them in a table instead and you can write a functin to retrive the error messages required.
    But if your requirement is for 'Package' then assuming that you store all the error messages in a table 'error_table' (say) following code may help you .
    CREATE TABLE Error_Table (
      Error_Code VARCHAR2(10),
      Error_Desc VARCHAR2(1024));Now insert your error codes and descriptions in this table.
    CREATE OR REPLACE PACKAGE pkg_Error_Handler
    AS
      FUNCTION f_Get_Error_Message(p_Error_Code  Error_Table.Error_Code%TYPE) RETURN VARCHAR2;
    END pkg_Error_Handler;/
    CREATE OR REPLACE PACKAGE BODY pkg_Error_Handler
    AS
      FUNCTION f_Get_Error_Message
           (p_Error_Code  Error_Table.Error_Code%TYPE)
      RETURN VARCHAR2
      IS
        lv_Error_msg  Error_Table.Error_desc%TYPE;
      BEGIN
        BEGIN
          SELECT Error_desc
          INTO   lv_Error_msg
          FROM   Error_Table
          WHERE  Error_Code = p_Error_Code;
        EXCEPTION
          WHEN No_Data_Found THEN
            lv_Error_msg := 'No such error code '
                            ||p_Error_Code
                            ||' defined in the system';
          WHEN OTHERS THEN
            lv_Error_msg := p_Error_Code;
        END;
        RETURN lv_Error_msg;
      END f_Get_Error_Message;
    END pkg_Error_Handler;
    /and you can call this packaged funtion from any exception block to get the error description.
    Regards,
    Abhijit.
    N.B.: Code not tested

  • I have three different listings for Bob Seger on my iPod (bob Seger, Bob Seger System and Bob Seger and The Silver Bullet Band) How can I put all 3 in the same artist folder without changing artist name?

    I have three different listings for Bob Seger on my iPod (Bob Seger, Bob Seger System and Bob Seger and The Silver Bullet Band) How can I put all 3 in the same artist folder without changing artist name?

    Can you just create a new "Playlist", name it Bob Seger and drag what you want into the Playlist.
    File/New Playlist

  • Hello Guys. I had problems in the Computer before and changed my HD. I saved in my all files documents in (Time Capsule). How can I put all my files, pictures documents on my new HD? Please Help. Thank You

    Hello Guys.
    I had problems in the Computer before and changed my HD. I saved in my all files documents in (Time Capsule). How can I put all my files, pictures documents on my new HD?
    Please Help.
    Thank You
    Julio Skov

    Hey
    Thank you very much for replay.
    Would you explain to me how can I do?
    I don't really understand these processes.
    Thak you very much
    Julio

  • HT201269 hi, my new device was set up in the store that I bought it from. How can I transfer all old text messages over to my new device? I have followed the icloud back up steps on this page. Please help, thank you.

    hi, my new device was set up in the store that I bought it from. How can I transfer all old text messages over to my new device? I have followed the icloud back up steps on this page. Please help, thank you.
    Its an iPhone 4
    Message was edited by: zzziggy85

    Here is how
    http://support.apple.com/kb/HT2109

  • How can I get past the error messages that keep popping up when I try to download Flash player?

    How can I get past the error messages that keep popping up every time I try to download anything?

    Hi
    Could you please let us know more about the error messages that you got?
    The following page has information on the error messages: http://helpx.adobe.com/content/help/en/flash-player/kb/installation-problems-flash-player- windows.html
    Thanks,
    Sunil

  • How can I import all my gmail contacts into iPad? I use iPad mini and the solutions available on the web are not compatible.

    How can I import all my gmail contacts into iPad? I use iPad mini and the solutions available on the web are not compatible.

    Hello and thanks for the answer.
    I meant by "not compatible" that all the solutions that I found on the web did not work, especially the "Microsoft exchange" one.
    Fortunately I found on the comments of the first website you mentioned the right answer for me, which I copy below:
    Tap Settings > Mail, Contacts, Calendars > Add Account > Other > Add CardDav Account.
    Enter the following information in the fields:
    Server: google.com
    User Name: Enter your full Google email address
    Password: Your Google account password
    Select Next at the top of the screen to complete the setup.
    After you have completed the setup, open the Contacts app on your device. Syncing should begin automatically.
    Additional Information
    Note: Make sure that SSL is enabled (under Advanced settings), and that the port is 443.
    If you are using application based special password go to https://accounts.google.com/Se... and instead of your password put that special code and u r done.

  • How do I put all my live feeds into one channel? I don't want to have to cick on each feed source separately.

    How do I put all my live feeds into one channel? I don't want to have to click on each feed source separately. Instead of one feed per website I want just ONE feed for all my sources together.

    Hi there old45,
    You may find the information in the article below helpful.
    iTunes 11 for Windows: Change where your iTunes files are stored
    http://support.apple.com/kb/PH12365
    Consolidate your files in the iTunes folder
    You can consolidate all the files in your library in the iTunes folder—for example, to make it easier to move your library to a new computer.
    Choose File > Library > Organize Library.
    Select “Consolidate files.”Files remain in their original locations, and copies are placed in the iTunes folder.
    To create folders (Music, Movies, TV Shows, Podcasts, Audiobooks, and so on) inside your iTunes folder, and place all your imported media files in the appropriate folders, select “Reorganize files in the folder ‘iTunes Media.’”
    Locate your iTunes files
    Do either of the following:
    Find out where a file is stored: Select the item in iTunes, and choose File > Get Info. The path to the file is shown at the bottom of the Summary pane (next to Where).
    Show the file in Windows Explorer: Select the song, and choose File > Show in Explorer.
    -Griff W.

  • I have 3 consecutive movie clips that I am trying to drop into the drop zone but it only recognizes the first one and only produces the firts one in a DVD. How can I drop all three  movie clips into one drop zone

    On IDVD, I have 3 consecutive movie clips that I am trying to drop into the drop zone to create a DVD but it only recognizes the first one I dropped and only produced the first one in a DVD. How can I drop all three  movie clips into one drop zone.

    I have had some luck doing the following: Export each clip from imovie as a quicktime clip. Open iDVD and create a new project. Import a few stills into iDVD and then click on the button that gets created to get into the screen where the individual slides appear. Drag each quicktime into that screen and arrange in the order you want. You can then delete the stills. The button that appeared when you dropped in the stills will launch a complete show.

  • How can I put all of my songs under artist. Some are only under songs?

    Some of my songs are listed under songs and not by artist.  How can I put them all under the artist category?

    Thank you, thank you THANK YOU Roger! You truly made my week! I would have never found thgat without you. Again, thanks a million!

  • HT1386 I do not have internet on my home computer, how can I put my pics and music into iTunes so I don't lose them all.

    How can I put my photos and music in iTunes so I don't lose them if something happens to my phone

    You don't need an internet connection to sync the phone with iTunes- cable or WiFi

  • How can I put songs on my ipod into my itunhes library?

    Help... I got a message saying "Warning! The registry settings used by the iTunes drivers for importing and burning CDs & DVDs are missing. This can happen as a result of installing other CD burning software. Please reinstall iTunes." I got that when I tried to open itunes after i installed a burning software. I am going to have to reinstall itunes, but I don't want to loose all my album art and play count and playlists. How can I save all this??

    Don't Worry, as long as your music is consolidated in your library, then your information (ie alb. art lyrics blah) will be saved! Just don't delete your music in your iTunes folder!
    -Guru

  • My drive collapsed. I have an external hard drive. How can I put all my files there, using disk utility?

    So my MacBook Pro collapsed one day, and it turns on but only "Restarts" and shuts itself down on the procesa. The only thing I have access to is that 'Command + R' thing. There I tried "Verifying" and "Reparing" the Diak but the message of "Cant repair disk backup as many files as possible, reformat the disk and restore" popped up. So I have am external hard drive with more than enough space to put all of my files in there. my question is: HOW DO I DO THAT? from disk utility. Can somone please help me? Please! Step by step cause ptherwise I will mess it up and I really dont want to lose all the memories I have in my computer.

    After you restart so you have access to Disk Utility, with the external drive connected, choose the external drive from the left sidebar of the DU window.  If the drive has not been formatted for the Mac, choose Partition from the buttons top center of the main window.  Give the drive a name, you can leave it as one partition if you like, make sure the format is set as Mac OS X Extended (Journaled), and the partition table is GUID.  Then Apply and acknowledge that you know this will erase the disk.
    Then go to the button that says Restore.  Drag and drop the internal drive, Macintosh HD is most common, to the Source box, and drag and drop the external drive to Destination box.  Then Restore.
    That will create a clone of the internal and that will be a bootable clone.

Maybe you are looking for

  • Using the Macbook with new LED Apple Cinema Display? Not a beginner's Q...

    Hi - I'm sort of cross-posting this because I'm not getting any answers in the Apple Cinema Display Forum, so here goes. So far, no one - not even a tech guy at a local Apple Reseller - has been able to help, so I've got my fingers crossed. I just go

  • Show/Hide certain items in an array of clusters

    I am trying to figure out how to programmatically show/hide certain items in a cluster (specifically an array of clusters).  I tried a couple of things but nothing worked for me.  On a similar note, I would like to be able to programmatically hide ce

  • Benchmarking Battery life of MacBook Pro 17"

    Hey guys, I tried to calculate the battery life of my 3/4 months old 17" book. This is how i conducted my test: 1) caliberated my battery, followed all 6 steps 2) turn off all the programs, including the ones in the task bar. 3) set the sleep timers

  • Export datapump is failing

    I am n Oracle 11.1.0.7.1 on HP Unix 11i. My export datapum was working for months, but now it fails consistently in a few minutes after it starts with follwing errors. I haved searched google and metalink and do not see any jobs in data_pump_jobs and

  • How to make a net browser using java

    We want to make an MultiLingual Explorer in JAVA .So please help me in the case thatfirst i want to do the coding of the basic interface as the menu option like open,save,save As etc.So how can i start it in java.Is their any builtin support or what