Solved

Throwing Exceptions

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Options in Zimbra Server 2 54
xampp tool 12 50
java jdbc batch example 8 34
how to see all occupied ports on windows 10 laptop 15 65
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

777 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