R
Richard Maher
Hi,
If when an object's constructor throws an exception that object has not in
fact been intantiated, then what happens to the bits/objects/variables that
were initialized/instantiated before the exception was thrown?
For example, if I open a file, or connect a socket while constructing an
object and then throw an exception before the constructor/instantiation
completes, then what happens to the file or socket connections that were
successfully instantiated?
a) Garbage Collected in the fullness of time as they're no longer
referenced?
b) Destroyed, and o/ride finalize() method that's called immediately?
c) It's considered extremely bad form to do this in a constructor. Have an
init() method instead?
d) Make sure you close the file/Socket before throwing the execption
e) Something else. . .
I know there stuff on the web, and I am looking it up as we speak, but there
is rather a lot of stuff on Exceptions so if someone here can help me out
I'd really appreciate it.
Cheers Richard Maher
If when an object's constructor throws an exception that object has not in
fact been intantiated, then what happens to the bits/objects/variables that
were initialized/instantiated before the exception was thrown?
For example, if I open a file, or connect a socket while constructing an
object and then throw an exception before the constructor/instantiation
completes, then what happens to the file or socket connections that were
successfully instantiated?
a) Garbage Collected in the fullness of time as they're no longer
referenced?
b) Destroyed, and o/ride finalize() method that's called immediately?
c) It's considered extremely bad form to do this in a constructor. Have an
init() method instead?
d) Make sure you close the file/Socket before throwing the execption
e) Something else. . .
I know there stuff on the web, and I am looking it up as we speak, but there
is rather a lot of stuff on Exceptions so if someone here can help me out
I'd really appreciate it.
Cheers Richard Maher