• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to trap an OutOfMemoryError in making Xml Dom

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello !
Can somebody help me to trap the OutOfMemoryError in case of building the Xml Dom. If i go on appending the child to the parent element indefinitely then java throws OutOfMemoryError which i have placed in the try-catch statement but whenever this error is thrown my code in catch statement is not executed.I am using Apache Xerces Parser with java for making Xml Dom.But in normal circumstances if i go on appending a string infinitely so that the jvm goes OutOfMemoryError i am able to successfully trap it in my catch statement.why is this so???
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OutOfMemoryError is a runtime error. Unlike checked exceptions that can be caught using the try-catch block, you can't trap RuntimeExceptions and subclasses of Error.
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
Jain Saurabh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ajith !
I think you are mistaken try executing this code, it will display an optionpane when it will go out of memory.
static String str="a";
public static void main(String args[])
{

try
{
for(;
str+=str;
}
catch(java.lang.OutOfMemoryError e)
{ javax.swing.JOptionPane.showMessageDialognull,"OutOfMEmory caught");
}
}
but this doesn't happen when i go on appending child in Xmldom using Apache xerces in java.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kindly switch off the smileys before posing code as the code portion turn into smileys. I hope was able to convey my message.
------------------
Thanks,
Hirdesh
 
Jain Saurabh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ajith !
I think you are mistaken try executing this code, it will display an optionpane when it will go out of memory.
static String str="a";
public static void main(String args[])
{
try
{
for(;;)
str+=str;
}
catch(java.lang.OutOfMemoryError e)
{ javax.swing.JOptionPane.showMessageDialognull,"OutOfMEmory caught");
}
}
but this doesn't happen when i go on appending child in Xmldom using Apache xerces in java.
Hope i have now articulated myself more clearly.
Hoping a technical response this time.

 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should have said " you [/i]shouldn't[/i] trap ...." instead of " you can't trap ". The Java API documentation for
java.lang.Error, the superclass of java.lang.OutofMemoryError says -


An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.
A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur.


Hope that helps!
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic