Solved

Throwing Exceptions

Posted on 2002-07-29
5
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

752 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