wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Error message print Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error message print" Watch "Error message print" New topic
Author

Error message print

nitinram agarwal
Ranch Hand

Joined: Jan 29, 2009
Posts: 83
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

Joined: Sep 26, 2009
Posts: 188
nitinram agarwal wrote:hI,

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6



Swastik
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

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.


[List of FAQs] | [Android FAQ] | [Samuh Varta]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
 
GeeCON Prague 2014
 
subject: Error message print