File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes exception types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exception types" Watch "exception types" New topic

exception types

RajivAwadhesh kumar

Joined: May 20, 2011
Posts: 24
Why java has 2 types of ecxeptions(checked and unchecked)? why should we not treat Unchecked exceptions e.g NullPointerException like
checked exceptions.. I mean what if we catch or declare a method as throwing a NullPointerException?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10828

Unchecked exceptions are typically generated because of sloppy programming. The code should be handling these cases where unchecked exceptions might arise. Propagating it so that someone else can handle it is a bad idea.
This is a good read

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
K Raghavendra

Joined: Oct 19, 2011
Posts: 1
Please read this link
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46412
Welcome to the Ranch K Raghavendra

It is often worthwhile going through the other fora RajivAwadhesh kumar; you would have found, for example, this.
Gaurav Raje
Ranch Hand

Joined: Jul 23, 2010
Posts: 136
This is quite a debated topic

In fact Microsoft found it useful to get rid of checked exceptions in C#... google up for their reasons as to why they felt it created problems
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Which will only lead to more unexpected errors for the user when programmers forget to catch these exceptions. The default "stack trace" dialog can be quite intimidating for most users.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: exception types
It's not a secret anymore!