Note that there are some explanatory texts on larger screens.

plurals
  1. POValidating constructor parameters, making sure parameters have the correct type
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COYou shouldn't "print error message" in a constructor, you should throw an exception (like in @Gordon's answer below). The constructor's purpose is to have a valid object after it's been invoked. By simply printing an error message instead of an exception, you will most likely end up with an invalid object that will screw up your whole program.
      singulars
    2. CONope, you shouldn't use exceptions. Use `assert()` to check variable types. Invalid arguments are foremost an development problem. This is were you want to catch such problems. Exceptions should be used when invalid arguments are to be expected at runtime, and if you can reasonably implement catch logic to retry with alternate arguments. E.g. [Assert vs Exceptions](http://stackoverflow.com/questions/117171/design-by-contract-tests-by-assert-or-by-exception/117247#117247) but also see duplicates..
      singulars
    3. CO@mario: I agree that `assert` can be used to check types internally. But not in a constructor. A bad argument passed to a constructor and it is an exception, an exception being an exceptional situation where the program cannot continue further. If a constructor has bad arguments passed to it, then it shouldn't continue further. Otherwise, like I said, you end up with an invalid object and a functioning program that takes the object as valid, and keep going until some major screw-up happens (garbage being inserted repeatedly in your DB per example).
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload