[Ethereum] Is it good practice to throw in Solidity Constructor

contract-designcontract-developmentsolidity

If I have a Smart Contract with a different Contract as parameter the parameter can be undefined which would be bad. Is it good practice to have a require(address(paramContract) != 0x0) statement in the constructor?

I'm tempted to do it because it makes sense but it sounds wrong to have a possible throw in the constructor

Best Answer

Think of the gas

Throwing an exception with require will save you or anyone trying to deploy the contract from wasting gas if the arguments are incorrect.

It's better that it causes an exception and alerts the creator that there's an issue with the contract's parameters, rather than simply allowing them to waste gas sending a transaction that will create a possibly irredeemably incorrectly configured contract.

If the contract has an error then the creator will get a notification from their client that the transaction won't succeed and then they can double check their parameters to see what they've done wrong.

Related Topic