There is no way to stop the creation of an object without throwing. The best you can do is set an "invalid parameter" flag that you have to check afterwards, and if true discard the object without using it.
With the requirements you have, it would probably be better to use a factory method to create the objects -- this way, you can make the checks before calling the constructor:
class item
{
int i;
public:
static item* create(int no) {
if (no < 0) {
return 0;
}
return new item(no);
}
private:
item(int no) {
}
};
You could use this like
item* myItem = item::create(-5);
if(!myItem) {
// failed
}
However, this forces you to allocate all item
instances on the heap.