Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > catching an OutOfMemoryError

Reply
Thread Tools

catching an OutOfMemoryError

 
 
Luke
Guest
Posts: n/a
 
      09-10-2005
My application was throwing an OutOfMemoryError. While looking for the
problem I was surprised to find that I could not catch the error and
print the stack trace. My catch statement seemed to be ignored and I
would only see a "java.lang.OutOfMemoryError" logged to the System.out
stream.

I was allocating large chunks of memory, so when the error happened I
assumed that there would be enough memory left for my application to
handle the error. I'm still curious about the failure to catch the
error.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-10-2005
On Sat, 10 Sep 2005 03:51:38 -0500, Luke <> wrote or
quoted :

>My application was throwing an OutOfMemoryError. While looking for the
>problem I was surprised to find that I could not catch the error and
>print the stack trace. My catch statement seemed to be ignored and I
>would only see a "java.lang.OutOfMemoryError" logged to the System.out
>stream.


You'd think there would be a run time switch to let you reserve X
bytes out of the pool, then on out of memory, throw those back into
the pool and trigger the exception, giving you a tiny bit of breathing
room to deal with the exception.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
ExGuardianReader
Guest
Posts: n/a
 
      09-10-2005
Luke wrote:

> My application was throwing an OutOfMemoryError. While looking for the
> problem I was surprised to find that I could not catch the error and
> print the stack trace. My catch statement seemed to be ignored and I
> would only see a "java.lang.OutOfMemoryError" logged to the System.out
> stream.
>
> I was allocating large chunks of memory, so when the error happened I
> assumed that there would be enough memory left for my application to
> handle the error. I'm still curious about the failure to catch the
> error.


Try

catch (Throwable)

 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      09-10-2005
ExGuardianReader wrote:
> Luke wrote:
>
>> My application was throwing an OutOfMemoryError. While looking for
>> the problem I was surprised to find that I could not catch the error
>> and print the stack trace. My catch statement seemed to be ignored
>> and I would only see a "java.lang.OutOfMemoryError" logged to the
>> System.out stream.
>>
>> I was allocating large chunks of memory, so when the error happened I
>> assumed that there would be enough memory left for my application to
>> handle the error. I'm still curious about the failure to catch the
>> error.

>
>
> Try
>
> catch (Throwable)


That or the catch clause was itself throwing OOME from its own
allocations. An empty catch clause would prevent the error displaying,
and so provide confirmation that the exception was actually being
caught. An important consideration when handling OOME, is are you making
sure you are not going to throw again before it is handled.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
John C. Bollinger
Guest
Posts: n/a
 
      09-10-2005
Luke wrote:
> My application was throwing an OutOfMemoryError. While looking for the
> problem I was surprised to find that I could not catch the error and
> print the stack trace. My catch statement seemed to be ignored and I
> would only see a "java.lang.OutOfMemoryError" logged to the System.out
> stream.


You may have been misunderstanding what you saw. You *can* catch
OutOfMemoryError, either explicitly or by catching Error or Throwable.
You should not, however, expect to get a stack trace out of one. The VM
creates an OOME instance at startup to throw at need, because if it
really does run out of memory and need to throw one then it may not at
that point have enough memory to create a fresh one. If, as you say,
"java.lang.OutOfMemoryError" was being printed then that probably *was*
the stack trace.

> I was allocating large chunks of memory, so when the error happened I
> assumed that there would be enough memory left for my application to

--^^^^^^^

You are unwise to write programs that depend on unfounded assumptions.
It will bite you. Moreover, if your assumption is reasonable but wrong
then it may only bite you infrequently -- such as only after you ship
the product.

> handle the error. I'm still curious about the failure to catch the
> error.


It sounds to me like the error was caught, and you just didn't recognize it.

--
John Bollinger

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OutOfMemoryError Dlugi Java 8 07-04-2007 07:11 PM
OutOfMemoryError in java app mike Java 0 09-08-2006 07:47 AM
OutOfMemoryError Marcelo Java 3 11-08-2005 02:00 AM
thread catching and stopping an OutOfMemoryError Ivan Villanueva Java 2 06-09-2005 06:06 AM
OutOfMemoryError Allan Bruce Java 3 06-30-2004 06:11 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57