[Gambas-user] Replace (Internal) Error Message
Bruce Steers
bsteers4 at gmail.com
Tue May 23 20:32:14 CEST 2023
On Tue, 23 May 2023 at 17:09, Bruce Steers <bsteers4 at gmail.com> wrote:
>
>
> On Tue, 23 May 2023 at 12:47, Hans Lehmann <hans at gambas-buch.de> wrote:
>
>> Hello.
>>
>> When I use the following procedure:
>>
>> Public Sub dcFlowername_Validate(Value As Variant)
>>
>> If IsNull(Value) Then
>> '-- Message.Warning(Subst("&1<br>&2<b> &3 </b>&4", ("No flower name
>> was entered!"), ("The data set is"), ("not"), ("saved!")))
>> '-- An *internal* error message is displayed!
>> Return
>> Endif
>>
>> End
>>
>> the same meaningless error message "Invalid value" is always displayed.
>>
>> Is there a way to replace this internal error message with a meaningful
>> error message of my own?
>>
>> With kind regards
>>
>> Hans
>>
>> How are you getting the error message?
> is it automatically printing or are you just reading Error.Text? because
> your function does nothing to reset or produce an error so the error message
> will be from what ever Try instruction last failed.
>
> if so use Error.Clear to clear the last error message before your function
> or do not read Error.Text if you have not used a method to clear/set it.
> And i assume you call
> dcFlowername_Validate(Null)
> not
> dcFlowername_Validate()
>
> the second type with no args needs...
> Public Sub dcFlowername_Validate(Optional Value As Variant)
>
> BruceS
>
Or maybe you need this...
See how you can set your own error message if you use Try and
Error.Raise("This Message")
If an Error is raised in the function you "Try" then Error is True and the
Error.Text can is set.
Like this...
Public Sub Main()
Try dcFlowername_Validate(Null)
If Error Then
Print Error.Text
Endif
End
Public Sub dcFlowername_Validate(Value As Variant)
If IsNull(Value) Then
'-- Message.Warning(Subst("&1<br>&2<b> &3 </b>&4", ("No flower name was
entered!"), ("The data set is"), ("not"), ("saved!")))
'-- An *internal* error message is displayed!
' -- Generate your own error text here...
Error.Raise(Subst("&1<br>&2<b> &3 </b>&4", ("No flower name was
entered!"), ("The data set is"), ("not"), ("saved!")))
Return
Endif
End
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230523/bdc91ca1/attachment-0001.htm>
More information about the User
mailing list