Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:05:20+00:00 2026-06-17T13:05:20+00:00

My question: How can i put the text e.printStackTrace prints into a JOptionPane window

  • 0

My question:
How can i put the text e.printStackTrace prints into a JOptionPane window

My code is currently as follows:
excuse the poor formatting 😛

try {
  //SOME CODE
} catch (Exception e) {
  e.printStackTrace();
  JOptionPane.showMessageDialog(null,
     "An unexpected error has occurred:\n" + e.getMessage() + '\n' + Thread.currentThread().getStackTrace() +  "\nPlease send this error to ." + email + "\nThanks for your help.",
     "Error", JOptionPane.ERROR_MESSAGE);
}

this both prints the stack trace in the command line interface(i am using terminal) and it creates a JOptionPane but NOT with the same info as e.printStackTrace(). when running my program from a jar file, the command line interface won’t be visible so the user will only get the JOptionPane window which doesnt have all of the info i need to succesfully identify the problem

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:05:21+00:00Added an answer on June 17, 2026 at 1:05 pm

    Here, This is just some general code I came up with that will get you the same output as e.printStackTrace().

    try {
        // some code
    } catch (Exception e) {
        StringBuilder sb = new StringBuilder(e.toString());
        for (StackTraceElement ste : e.getStackTrace()) {
            sb.append("\n\tat ");
            sb.append(ste);
        }
        String trace = sb.toString();
        // Now, trace contains the stack trace
        // (However, you can only use it inside the catch block)
    }
    

    However, as was previously mentioned, you probably want a window in which you can scroll, as I don’t think it’d fit very well in a JOptionPane.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe a very simple question. How can I put in this code <Query> <Where>
How can I put a question mark above a less-than-or-equal-to symbol( \leq ) in
Simple question, I know, but I can't seem to find a way to put
Right bit of a simple question can I input nText into a pivot table?
Can we put into a single regular expression , boolean logic : line starts
(Note: This is a follow up to my question Can jQuery.getJSON put a domain's
I'm trying to figure out how I can put text including line-break from a
Question Can I style just a part of a single character? Meaning CSS attributes
Short Question: Can I specify wildcards for custom console folding? If so, what is
My question can be boiled down to, where does the string returned from stringstream.str().c_str()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.