Re: How to drop this exception?
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Mon, 25 Sep 2006 15:18:30 GMT
"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
.
- Follow-Ups:
- Re: How to drop this exception?
- From: Ikke
- Re: How to drop this exception?
- References:
- How to drop this exception?
- From: Ikke
- How to drop this exception?
- Prev by Date: Re: Specific Cloning Question
- Next by Date: Re: Specific Cloning Question
- Previous by thread: How to drop this exception?
- Next by thread: Re: How to drop this exception?
- Index(es):
Relevant Pages
|