Link to home
Start Free TrialLog in
Avatar of mdoland
mdoland

asked on

Java design question about constructors with exceptions

I don't like to have Constructors that can fail and throw a bunch of exceptions. Especially not exceptions that are reasonable to occur sometimes and that you expect to be possible to handle.

In this case, there is a hardware device that hopefully is connected to the computer.
However, if it isn't I will get an exception in the managing class (a singleton) in its java constructor.
I want to work away from that, but don't like the idea of having to call init on the singleton to get it working.
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's true there are times when you need to throw an exception, but if you can avoid it, you should
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial