Solved

Throwing Exceptions

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 72
Crystal Reports Licensing Questions 4 60
Eclipse Java import and method not resolved 4 76
Netbeans and org.apache.commons.lang3 issue 3 24
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

756 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