• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

exception handling

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why should exception handling techniques not be used for conventional program control?
What is the difference between try block and a catch block?
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two reasons:
1) Using exceptions for flow control basically means that you are using exceptions as a goto mechanism, and gotos make for messy, spaghetti code.
2) Creating and catching an exception brings overhead of creating an object. This is much slower and more expensive than using standard flow-control.

The try block is where your normal code codes. The Catch block is where you put code that deals with the problem that caused the exception.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why should exception handling techniques not be used for conventional program control?
This is the third time that this question (more or less) has been asked over the past month. Unfortunately, searching isn't working very well right now. I found one of the past conversations (but it isn't exactly the same topic).
The chapter on exception handling of Bruce Eckel's book, Thinking In Java, is worth reading.
Also, you may want to try a quick search on google and through the JavaWorld articles for topics such as "exception handling philosophy".
What is the difference between try block and a catch block?
For a decent introduction to the syntax and structure of exception handling in Java, take a look at The Handling Errors With Exceptions Lesson of Sun's Java Tutorial and chapters 80 and 81 of Bradley Kjell's Introduction to Computer Science using Java.
Good Luck.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Performance is also a reason. You run about
18% slower when you use Exception Handling for
"normal" control flow ( for example, breaking
out of a look when it reaches it's highest
value or some "special" value before the end. ).
The Performance book from Sun ( Java Platform
Performance ) also has an excellent writeup
on the performance penalties when "mis-using"
Exception Handling:
http://www.amazon.com/exec/obidos/ASIN/0201709694/ref=ase_internetconcierg/
I agree on Bruce Eckel "Thinking in Java" as a
good recommendations and understanding
for Exception Handling.
-----------------------------------
Considering the Certified Java Programmer Exam?
Get JCertify!
http://www.enterprisedeveloper.com/jcertify
The Best investment in your career you will make all year
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic