X
xxxxyz
Hi,
I want to create a class with a constructor which can fail (for example
if (..) fail
. When constructor fail I want the variable to point to
null. Example:
class PosInt{
int i;
public PosInt(int j)
{
if (j<0)
?fail?;
i=j;
}
}
.....
PosInt m=new PosInt(-5); //after this I want m=null
How can I do this (What to put instead ?fail?)? Is this a good practice
and style?
Thanks.
I want to create a class with a constructor which can fail (for example
if (..) fail

null. Example:
class PosInt{
int i;
public PosInt(int j)
{
if (j<0)
?fail?;
i=j;
}
}
.....
PosInt m=new PosInt(-5); //after this I want m=null
How can I do this (What to put instead ?fail?)? Is this a good practice
and style?
Thanks.