Solved

Throwing Exceptions

Posted on 2002-07-29
5
230 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 128
Java / Linux and Regular Expressions 11 71
eclipse java  build path 6 45
Java Timer (static) 9 36
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

863 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