Results 1 to 7 of 7
  1. #1
    neveser is offline Member
    Join Date
    Nov 2012
    Posts
    40
    Rep Power
    0

    Default Is it possible to thrown an exeption to a jtextarea?

    I'm trying to throw the exception text into a jtextarea.

    I tried
    Java Code:
    throw new IllegalArgumentException(outputTextArea.append("Invalid input"));
    but that doesn't work. I get 'void' type not allowed here.
    Not sure how to do this. Doesn't seem like it should be that hard.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Is it possible to thrown an exeption to a jtextarea?

    Define 'throw the exception text into a jtextarea'...do you mean append the stack trace of the exception to a JTextArea? You could catch the exception and append the stack to the JTextArea, or use a Logger, or even redirect the standard error stream which is used in the Throwable.printStrackTrace() method. But given the example if you are worried about reporting an IllegalArgumentException to a user, you might wish to reconsider your design as this Exception (IMO) is more of a lower level Exception that results from improper use of an API (eg the programmers fault) rather than improper use of software (the users fault) that a user must be notified of.

  3. #3
    neveser is offline Member
    Join Date
    Nov 2012
    Posts
    40
    Rep Power
    0

    Default Re: Is it possible to thrown an exeption to a jtextarea?

    I want to report the error to the user. In this case if the user enters 0 for a particular value, I want them to know that value was not acceptable.

    I'm a total noob at this and I was playing around with the idea. It seems like it should be fairly easy to do but my brain and java don't see eye to eye.
    I had a bit of a tough time with VB last year and this is proving to be even less "enjoyable" than that experience was.

    My programming knowledge is from the days of BASIC and line numbers, back when line numbers actually meant something to the program.

    Thanks for the info, gives me something to chew on and play with.

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Is it possible to thrown an exeption to a jtextarea?

    I want to report the error to the user. In this case if the user enters 0 for a particular value, I want them to know that value was not acceptable.
    If you want to report a problem to the user, the look into using a JOptionPane (a typical user won't understand a full stack trace) - catch the exception and and report a more meaningful message to the user
    How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

  5. #5
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Is it possible to thrown an exeption to a jtextarea?

    Or if you really want to show the exception messages/stacktrace to the user, you could use the JXErrorPane from the SwingX-project.

  6. #6
    Potato is offline Member
    Join Date
    Dec 2011
    Posts
    25
    Rep Power
    0

    Default Re: Is it possible to thrown an exeption to a jtextarea?

    You can get the stack trace as a string like this:

    Java Code:
    		try {
    
    			...
    
    		} catch (Exception e) {
    			ByteArrayOutputStream out = new ByteArrayOutputStream();
    			e.printStackTrace(new PrintStream(out));
    			String stackTrace = new String(out.toByteArray());
    		}
    Then you just need to append it to your text area

  7. #7
    neveser is offline Member
    Join Date
    Nov 2012
    Posts
    40
    Rep Power
    0

    Default Re: Is it possible to thrown an exeption to a jtextarea?

    Wow!

    Lot of suggestions in here, thanks guys! :)

Similar Threads

  1. null pointer exeption : how solve it ?
    By miki_ir in forum New To Java
    Replies: 11
    Last Post: 09-05-2011, 02:38 AM
  2. Null Pointer Exeption
    By Aldane in forum AWT / Swing
    Replies: 3
    Last Post: 03-19-2011, 10:11 AM
  3. NullPointer Exeption, but why?
    By warchieflll in forum New To Java
    Replies: 10
    Last Post: 12-09-2010, 04:34 PM
  4. exeption haldling
    By sniffer139 in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-23-2010, 09:38 AM
  5. null pointer exeption
    By mj23brm in forum New To Java
    Replies: 4
    Last Post: 02-10-2009, 11:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •