• 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

Exceptions

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java ,we have runtime and user defined exceptions.
for runtime ,the JVM will handle.
and the user defined are handled by the user by using try and all those.
my question is why we need user defined exceptions?
coz we can handle those by using some conditions also
then wats the need for user defined exceptions?

thanks
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi (I'm excited this is my first post!)

As an answer to your inquiry: We can opt to use, suggested to use appropriately, customized exceptions so we can take advantage of one of the many benefits of Object-Oriented Programming which is code-reusability. That
instead of re-writing similar code for handling faulty conditions, we call our custom-written exceptions, similar to instantiating objects of another class when we need them. No need to re-invent the wheel.

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java there are checked and unchecked exceptions. It is a bit inaccurate to talk about "user defined exceptions", because you can create your own checked as well as unchecked exceptions. So, user defined exceptions are not necessarily checked exceptions.

The advantage of checked exceptions is that they provide safety: they force the programmer to think about error conditions that can happen, because you are required to handle the exception - either by adding a try-catch block, or adding a throws-clause to the method declaration.

On the other hand, there are people who think that checked exceptions are not needed. Checked exceptions are a feature that is unique to Java, no other programming language has the same concept.

For more details about how exceptions work in Java, see The Java Tutorial - Exceptions.

Critique on checked exceptions:

Bruce Eckel: Does Java need Checked Exceptions?

The Trouble with Checked Exceptions (about why C# does not have checked exceptions; Anders Hejlsberg, the designer of the C# language, explains what he thinks are issues with checked exceptions)

Avoiding checked exceptions

And Shelemiah, welcome to JavaRanch!
 
Shelemiah Castro
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And Shelemiah, welcome to JavaRanch! [jumpingjoy]



Thanks Jesper.
 
reply
    Bookmark Topic Watch Topic
  • New Topic