A ANC Software New Member Licensed User Longtime User May 7, 2018 #1 Hello, I have a sub which helps me to read map objects as follows: Code: Copy Sub GetTextItem(Rec As Map, FieldName As String) As String Dim ret As String ret="" Try ret=DecodeString(Rec.Get(FieldName)) Catch Log("GetTextItem") End Try Return ret End Sub The problem is that if I call GetTextItem passing a List object instead of a Map object, the compiler doesn't warn me about the error, but it will be thrown at Runtime. Example: Code: Copy dim ls as List ls.initialize 'add some items log( GetTextItem(ls, "DUMMY") ) ' this should be handled by the compiler Further, I noticed that in this case the Application_Error didn't fire. Any help is much appreciated, thank you. Antonello
Hello, I have a sub which helps me to read map objects as follows: Code: Copy Sub GetTextItem(Rec As Map, FieldName As String) As String Dim ret As String ret="" Try ret=DecodeString(Rec.Get(FieldName)) Catch Log("GetTextItem") End Try Return ret End Sub The problem is that if I call GetTextItem passing a List object instead of a Map object, the compiler doesn't warn me about the error, but it will be thrown at Runtime. Example: Code: Copy dim ls as List ls.initialize 'add some items log( GetTextItem(ls, "DUMMY") ) ' this should be handled by the compiler Further, I noticed that in this case the Application_Error didn't fire. Any help is much appreciated, thank you. Antonello
Erel B4X founder Staff member Licensed User Longtime User May 7, 2018 #2 In some cases the compiler will show a warning for wrong types, however there are many cases where the compiler doesn't know whether casting is allowed so it tries to cast. In such cases the error will happen at runtime. ANC Software said: Further, I noticed that in this case the Application_Error didn't fire. Click to expand... Make sure to run your app in release mode. If it doesn't work then please start a new thread in the questions forum.
In some cases the compiler will show a warning for wrong types, however there are many cases where the compiler doesn't know whether casting is allowed so it tries to cast. In such cases the error will happen at runtime. ANC Software said: Further, I noticed that in this case the Application_Error didn't fire. Click to expand... Make sure to run your app in release mode. If it doesn't work then please start a new thread in the questions forum.