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 Using try-catch for program logic. 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 "Using try-catch for program logic." Watch "Using try-catch for program logic." New topic
Author

Using try-catch for program logic.

Tim McMurry
Greenhorn

Joined: Oct 31, 2009
Posts: 22
Hi,

I am reading about reflection at the moment. In the book the following example is given. It shows a method which tries to locate
a method defined by its name and type of its arguments for a specified class. It first looks to see if the method is a declared method in the class
and otherwise traveses the inheritance-tree above it, to see if it has inherited the method:


Is it generally ok coding to use try-catch for the purpose of handling program "flow" ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

What do you think? Does it add to the clarity of the code? Is there a simpler way to accomplish the same thing?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38040
    
  22
And is NoSuchMethodException the most appropriate class if null is passed?
Tim McMurry
Greenhorn

Joined: Oct 31, 2009
Posts: 22
Hi,

thanks for the inputs. I get new homework by asking a question, when is it due ?!
I am reading up on the exception-handling mechanism to come up with qualified arguments against. To my beginner-eyes
it seems at first that it would be hard writing the code so compactly without using try-catch.
It might be time for learning to use a profilimg tool to compare the time usage for the method using try-catch with a rewritten version of it.
Only problem is, I love the commandline and think IDE's are for when you have learned enough to be able to do by hand everything your IDE can.
But there doesnt seem to be many options for commandline profiling
 
 
subject: Using try-catch for program logic.
 
Similar Threads
To map backing bean from a selected drop-down value
Class.forName()
Passing dynamically created arguments to method
java reflection to invoke parent class method
java beans propertyDescrptor