• Post Reply Bookmark Topic Watch Topic
  • New Topic

Anonymous Inner Class Throw Exception  RSS feed

 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I couldn't find much information on this from Google. I have an anonymous inner class and I am not wanting to do a try catch statement just to print a stack trace or log the exception. I can't find a solution and this exception is stacked multiple times from a fileWriter in another class. Anyway to solve this without a try catch?

 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which bit of that code is throwing an exception?

What should the user see if there is a problem (which is presumably what the exception means) with whatever it is that's being done?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume this is a Swing code. Handling uncaught exceptions in Swing is messy in older versions of Java (Java 6 or older). Which Java version are you using?
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you called dispose() in that method? And what is loadButtons? you should avoid changing the display from a Listener if possible.
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why have you called dispose() in that method? And what is loadButtons? You should avoid changing the display from a Listener if possible.




Load buttons




 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Which bit of that code is throwing an exception?

What should the user see if there is a problem (which is presumably what the exception means) with whatever it is that's being done?


Im just trying to find out how to throw the exception in an anonymous inner class to cut down on the checked exceptions....but after reading this checked vs unchecked exceptions it is bad practice to just throw an exception......

My next question is then how to handle a IOException for reading and writing to files.....
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Vajsar wrote:I assume this is a Swing code. Handling uncaught exceptions in Swing is messy in older versions of Java (Java 6 or older). Which Java version are you using?


Latest version v1.8 something



Campbell Ritchie wrote:Why have you called dispose() in that method? And what is loadButtons? You should avoid changing the display from a Listener if possible.


dispose is called to close the JDialog and return the user back to the JFrame


 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the Java tutorials about file input?

As for how to handle Exceptions: start by thinking what you will do if something goes wrong.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!