• 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

Throwing own Exceptions

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can throw your own exceptions and errors.

There are the checked exceptions which have to be handeled either with thows or with try/catch and the unckecked excetpions (RuntimeExcpeption and its subclasses). It is possible to throw an own Error as the following code shows.



In this case there isn't thrown an Exception but an Error. I somewhere read, there would be thrown a Throwable, i.e. a Superclass of Error? Is that true?
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



In this case there isn't thrown an Exception but an Error. I somewhere read, there would be thrown a Throwable, i.e. a Superclass of Error? Is that true?



throw takes any form of throwable object as long its subclass of Throwable. Here Class AssertionError and Error are subclass of Throwable and hence possible.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic