• 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

Exception and JVM

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True or false
JVM will not throw any exceptions. Only programs will throw exceptions.

 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All subclasses of RuntimeException (which is an Exception) and Error are constructed and thrown by JVM at appropriate places, when need comes. All checked exceptions are checked by the compiler whether they are caught properly. Otherwise compile time error occurs. Both Exception and Error can also be thrown by programs through throw new aSubClassOfThrowable(); statement. If the program throws a checked exception(all subclasses of class Exception excluding RuntimeException ) they must be enclosed by try..catch/try..finally/try..catch..finally statements.
So the above statment is not true
regds
maha anna
[This message has been edited by maha anna (edited March 12, 2000).]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From M.A.'s post:

If the program throws a checked exception(all subclasses of class Exception excluding RuntimeException ) they must be enclosed by try..catch/try..finally/try..catch..finally statements.


...or they must be declared in the throws clause of the appropriate method(s). As I'm sure you know - just wanted to be complete.
As for Divakar's original question: false, as m.a. said. Exceptions are always thrown by the JVM, usually in response to something in the program. But the program isn't necessarily the cause. Example - if the program is reading data through a connection across the internet, the read() method is declared with a "throws IOException". If I then reach over to the phone line that connects my computer to the internet, and disconnect it, then the JVM will throw an IOException of some sort. Did the program cause this, or did I? I'd say that I did.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Jim , your statement completes the previous post.
regds
maha anna
reply
    Bookmark Topic Watch Topic
  • New Topic