Solved

Throwing Exceptions

Posted on 2002-07-29
5
228 Views
Last Modified: 2010-03-31
Out of laziness and inexperience, I started developing an application where, when I'm declaring a method, I say that it throws Exception, rather than the actual exception that it does throw ( eg SQLException ). Unfortunately, the rest of the team have taken the same standpoint and we know have about 20,000 libes of code where the majority of the declarations are of the form
public void fred() throws Exception

Is it worth going back and doing the job properly? Does it make much difference?

Dave
0
Comment
Question by:howesd
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 7185009
> Is it worth going back and doing the job properly?

can you define "properly" ?

if you need only one kind of Exception (SQLException) global find&replace will "solve" the problem.
0
 
LVL 1

Author Comment

by:howesd
ID: 7185018
It's quite a big web-app with about 70 of our own expection classes plus all the normal ones you'd expect ( NullPointer, IOException etc )

I suppose the question is "Is public void fred() throws SQLException, NullPointerException *better* than public void fred() throws Exception"?

The trouble is, I'm not really sure what I mean by "better". Are there performance implications or is it purely a stylistic issue?

Sorry that I'm not being more precise about this ..

Dave
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7185054
NullPointerException is RuntimeException, so it's useless to  declare
throws NullPointerException

declaring
throw YourOwnCheckedException will allow compile-time-check that all typed Exceptions are catched wherever they may be thrown.
0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
ID: 7185056
throwing typed exceptions allow you to handle each type differently (with different catch code)
0
 
LVL 1

Author Comment

by:howesd
ID: 7185058
It's quite a big web-app with about 70 of our own expection classes plus all the normal ones you'd expect ( NullPointer, IOException etc )

I suppose the question is "Is public void fred() throws SQLException, NullPointerException *better* than public void fred() throws Exception"?

The trouble is, I'm not really sure what I mean by "better". Are there performance implications or is it purely a stylistic issue?

Sorry that I'm not being more precise about this ..

Dave
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now