File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Exceptions list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exceptions list" Watch "Exceptions list" New topic

Exceptions list

garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
Hi helper,
I have incountered a problem catching an error.
The error is a dublicate primary key that the user might want to insert into a db.
I f he tries there an error raises up and i would like to catch this specific error.
1.What is the name of the exception that catchs this error?
2.Do you know of a source that might lead me to a list of exceptions in java?
Alain Boucher
Ranch Hand

Joined: Feb 25, 2003
Posts: 51
The execption raise by a duplicate key is a java.sql.SQLException... like any other problem during a SQL query. Log the exception message to know why it crash. DUplicate primary key is a programatic exception, it is not suppose to happen in a well done program, so there is no specific exception for that problem

Alain Boucher<br />Spare-Brain Consultants Inc.<br />SCJ2P,SCWCD,
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Do you know of a source that might lead me to a list of exceptions in java?

Maybe the Java api (just a wild guess). API

Please ignore post, I have no idea what I am talking about.
garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
Thanks for the quick replys,
Duplicate keys is avoided but for any case I thought of creating a catcher that will catch it if... as I understood the exception does not exist.
Thanks again.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

garfild: I see your problem here. Although you know it is a SQLException, you want to distinguish between different sql exceptions and take action only on a primary key violation. This can be done, but with some portability warnings.
1. Find out what the exact error message of the SQLException.
2. have a routine that checks for this specific error message. If it matches, then you know that you have your primary key violation exception and can act accordingly.

The portability issue here is that if you change databases or even drivers, the error messages will be different. This will introduce errors into the exception handling routines.
Some other ideas are to centralize the error messages into one class. This may ease the transition to a new driver so you are not frantically checking thousands of lines of code changing all your hard coded messages to the new message.
I agree. Here's the link:
subject: Exceptions list
It's not a secret anymore!