Re: will map:put() never fail?

new topic     » goto parent     » topic index » view thread      » older message » newer message
DerekParnell said...
euphoric said...

Shouldn't map:put() be a function in case it needs to report an error? I don't see anything like "map:get_error()" either...

Or maybe map:put() will never fail?

It can fail, but if it does it causes a program fail too. It can fail for these reasons ...

  1. The MAP ID is wrong. Either an invalid value or it refers to an object which isn't a map.
  2. The OPERATION argument is not a valid value.
  3. The OPERATION argument is invalid for the case when the KEY does not exist in the map.
  4. The computer's RAM has been exhausted.


I think that the idea was that if one of these situations arose, then the application is already compromised and cannot continue anyhow.

  1. We should return BAD_MAP_ID (-1)
  2. We should return BAD_OPERATION_VALUE (-2)
  3. We should return KEY_DOES_NOT_EXIST (-3)
  4. We should return OUT_OF_MEMORY (-4), if possible

Otherwise, we return 1 (SUCCESS!).

It could STILL be used as a procedure, because 4.x does not require you to use the return value. So it won't break code if we turn this into a function.

OR, we could put it on the user to test for all those things first, which is not very nice. :)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu