aspose file tools*
The moose likes Beginning Java and the fly likes exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exception handling" Watch "exception handling" New topic
Author

exception handling

Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
why should exception handling techniques not be used for conventional program control?
What is the difference between try block and a catch block?
Lance Finney
Ranch Hand

Joined: Apr 26, 2001
Posts: 133
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.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
David Brafford
Ranch Hand

Joined: Feb 11, 2001
Posts: 91
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception handling
 
Similar Threads
try catch block
Prepared Statements
Help me in Exception Handling
Is finally, really finally
performance degradation in using try/catch