This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes catching run time exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "catching run time exception?" Watch "catching run time exception?" New topic
Author

catching run time exception?

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Why we should not catch java.lang.RunTimeException or it's sub classes???

Thanks a lot.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Because a runtime (unchecked) exception usually means that there's a bug in your program.

Usually you don't want your program to continue running if an unexpected exception happens, because it means that your program is in an undefined state, and it doesn't make much sense to keep running if the program is in an undefined state.

Some people follow a different philosophy, for example in the Spring framework, unchecked exceptions are used almost exclusively.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

In a professional system though, you want to catch all exceptions on the highest level so as to present a clean error message saying something failed, often a message saying "Error, Please contact an Administrator". It doesn't do much good if customers using your system recieve a large stack trace.


My Blog: Down Home Country Coding with Scott Selikoff
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Jesper de Jong:
Because a runtime (unchecked) exception usually means that there's a bug in your program.

Usually you don't want your program to continue running if an unexpected exception happens, because it means that your program is in an undefined state, and it doesn't make much sense to keep running if the program is in an undefined state.

Some people follow a different philosophy, for example in the Spring framework, unchecked exceptions are used almost exclusively.


I agree, that they come due to programming fault. But we can't show exceptions to user???

What you say???

Thanks.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Originally posted by rathi ji:
I agree, that they come due to programming fault. But we can't show exceptions to user???

What you say???

Thanks.


Ofcourse you can and you should, see Scott's answer.
But ofcourse your software should not contain bugs that cause runtime exceptions in the first place...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: catching run time exception?
 
Similar Threads
JavaRanch Olympics
WA #1.....word association
JSP init parameters.
about object serialization
5 letter scrabble