• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error message print

 
nitinram agarwal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hI,
I have a code which is throwing "java.lang.OutOfMemoryError:" sometime,
I want to print some specific value in my catch block before this error message.
please let me know how to do this.

for ex here is the code snippet

try {
do_something();
} catch(Exception e) {
print_some_error_message; // I want to print this error message if outof memory is thrown
//usual exception is thrown here
}
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nitinram agarwal wrote:hI,

 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Throwable class has two subclasses: Error and Exception. Take a look at the inheritance tree of the OutOfMemoryError class. Also, check if you should catch such an error and if you do, what you can or cannot do.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep in mind that an OutOfMemoryError (OOME) indicates that the JVM doesn't have enough memory for some operation. This can very well mean that your code will cause another OOME, because it's quite likely there still isn't enough memory.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:

Why wouldn't you just catch the OutOfMemoryError?

In any case, you should consider whether or not this is something your application should even be catching: errors indicate a *serious* problem, one which is likely to prevent further execution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic