• 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 Handling

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

Can someone explain me what is the aim and benefit of Exception Handling mechanism in Java?


Waiting for enlightenment.....
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pretend, you want to print string *JAVARANCH* but, before it reach the print statement , your running thread encouter a statement like int i = 5/0 . so now how do you print the string ?
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean to say we can direct what should happen if at all a exception come at run time....

In this very specific case if at all the exception arises and we still want to print *JAVARANCH* then we can put it in finally....

So, the moral is you can command what should happen when an exception is encountered by way of exception handling mechanism.....hummmm

Good point.....What more?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With exception handling you can make your application robust. In your applications if you are doing things like reading/writing files or making network connections, then error conditions are inevitable. With exception handling you can handle any errors so that your application can keep running instead of crashing...
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok!

So, exception handling mechanism in Java provides following benefits:

1) you can command what should happen when an exception is encountered by way of exception handling mechanism
2)It makes our application robust. When a runtime exception arrises, we can handle it using this mechanism and move ahead, which would enable our program to keep running rather than crashing down.

What more people!
Keep coming....
We are going to explore the benefits of Exception Handling Mechanism to its core
 
Ranch Hand
Posts: 101
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exceptinos can prevent from an unexpected behavior and a type of an exception can tell you what went wrong. For example if you see an ArrayIndexOutOfBoundsException you know that you have a problem with an array. All objects which extend Throwable have a public void printStackTrace() method which can show you which element (constructor, method, etc) throws an exception and point you a line in code with a problem.
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok!

So, till now we got the following:

1) you can command what should happen when an exception is encountered by way of exception handling mechanism
2)It makes our application robust. When a runtime exception arrises, we can handle it using this mechanism and move ahead, which would enable our program to keep running rather than crashing down.
3)Exceptins can prevent from an unexpected behavior and a type of an exception can tell you what went wrong and WHERE it went wrong.

Waiting for more.....

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

Prateek Rawal wrote:
... a type of an exception can tell you what went wrong and WHERE it went wrong.


a type of an exception cannot tell you where exception was thrown but a stack trace can.
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay,,,,
I didn't meant to say exception tells that where the exception occurs but i meant to say Exception Mechanism tells us that, but i worded it incorrectly.

Thanks Mark,

so the edited list is:


1) you can command what should happen when an exception is encountered by way of exception handling mechanism
2)It makes our application robust. When a runtime exception arrises, we can handle it using this mechanism and move ahead, which would enable our program to keep running rather than crashing down.
3)Exceptions can prevent from an unexpected behavior and a type of an exception can tell you what went wrong and the printStackTrace() (an element of Exception Mechanism) can tell you WHERE it went wrong.
 
reply
    Bookmark Topic Watch Topic
  • New Topic