KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Use throw to give specific errors when checking object property type
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: December 21, 2023

When passing an object as a parameter into a method, the typing of the object’s properties should be checked for consistency. If an object property does not have the correct type, the throw command can be used to give a specific error. For example:

#DECLARE($person : Object)

If (Value type($person.name)=Is text)
   // do something
Else
   throw(-1202; "Person's name should be a text.")
End if

The method above receives a “person” object with a “name” property. The “name” property should always be text, so throw a specific error if the typing is incorrect. This makes it easier to track down type inconsistencies in object properties.