Re: How to drop this exception?




"Ikke" <ikke@xxxxxxx> wrote in message news:Xns9848DA26FC745ikkehierbe@xxxxxxxxxxxxxxxxx
Hi everybody,

Here is some code I've been working on...

--- code ---
String connect = "jdbc:mysql://code/db?user=me&password=none";
Driver driver = new com.mysql.jdbc.Driver();
dbc = new DatabaseConnection();
dbc.openConnection(driver, connect);
--- /code ---

Those last two lines are needed to use a custom class from some package I
received. The openConnection method expects, as you can see, a driver and a
connectionstring.

No problems for that last part - but in order to create a new Driver
object, I need to catch the SQLException which can be thrown by the Driver
constructor.

The reason to use the package in the first place was because it hides all
that and simply returns a boolean (connected / not).

Is it possible to:
a) construct a new Driver object without having to catch the SQLException
(probably not, and not a very good idea imho)

You'd have to modify the code for Driver to do that. If I understood correctly, Driver is part of a 3rd party library, so you can't modify the code for Driver.

b) pass in a Driver object, and let the method handle the exceptions

To actually pass in the object, you'd have to construct the object, in which case you'd have to call the constructor, putting you right back at square one.

c) pass in the name of a class which needs to be instantiated (best option
I guess)

Possible, but this uses reflection, and generally it's better to use a non-reflective solution in preference to a reflective one.

Is there a special reason you can't just catch (or throw) the exception?

- Oliver

.



Relevant Pages

  • Re: **2009 Pool** Driver / Constructor championships
    ... Championship, and which team wins the Constructors Championship, reply to ... NO PREDICTIONS FOR FIRST RACE PLEASE. ... Driver: Felipe Massa ... Constructor: Renault ...
    (rec.autos.sport.f1)
  • Re: **2009 Pool** Driver / Constructor championships
    ... Championship, and which team wins the Constructors Championship, reply to ... NO PREDICTIONS FOR FIRST RACE PLEASE. ... Driver: Felipe Massa ... Constructor: Ferrari ...
    (rec.autos.sport.f1)
  • Re: linux-next-20081120 - staging - meilhaus driver build fails
    ... PERROR("Can't get %s driver module constructor.\n", ... ("Can't get device instance of %s driver module.\n", ...
    (Linux-Kernel)
  • Re: Hooray for test day commonsense
    ... Not only do you get a situation where the struggling teams get extra testing to hopefully close up the gaps, but it makes the constructors points more valuable to the teams. ... Also, you get a situation where a team puts all its effort in to one driver to win the WDC, but comes second in the WCC. ... one down side is that previous years constructor points are not a good indicator of current years form or testing needs. ... negociate the base line each year depending on reg changes? ...
    (rec.autos.sport.f1)
  • Re: **2009 Pool** Driver / Constructor championships
    ... Championship, and which team wins the Constructors Championship, reply to ... NO PREDICTIONS FOR FIRST RACE PLEASE. ... Driver: Felipe Massa ... Constructor: Renault ...
    (rec.autos.sport.f1)