[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: TestError
[Thread Prev] | [Thread Next]
- Subject: Re: TestError
- From: CD <dessere.claude@xxxxxx>
- Date: Tue, 11 Nov 2025 10:48:51 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Yes, I did some tests.
TestError.txt is in the project's Data folder.
If I use, for example:
Try File.Load("TestError.txt")
If Error Then
Print Error.Text
Print Error.Code
Print Error.Where
End If
then File.Load("TestError.txt") does not generate an error,
"If Error" is False
If I remove the "Try"
then File.Load("TestError.txt") does not generate an error, but
"If Error" is True with
Null object
13
[gb.gui.base].ListBox.GridView_Data.145
the previous error
So what I understand from all this is:
1) Don't confuse the ERROR flag (as written in the documentation
https://gambaswiki.org/wiki/lang/error)
with the Error class, except that in the code editor the "ERROR" flag becomes
"Error"...
2) The ERROR flag can be set to False, and the Error class can contain a
previous error that wasn't cleared with Error.Clear.
If the ERROR flag is set to True, then the Error class contains the last error
that occurred.
Is that correct?
3) Do not test the Error flag without a
Try Instruction
If Error Then ...
or a
Instruction
Catch
...
4) What is the difference between a
Try Instruction
If Error Then ...
and a
Instruction
Catch
Local in the sub or function for the first
and general and deep for the second.
Is that correct too?
Thank you for your clarification.
Le mardi 11 novembre 2025 à 06:51 +0000, Bruce Steers a écrit :
> Do you mean Error flag or Error.Text ?
> Error should be false.
> Try the following to test for a valid error.
>
> If Error Then Print Error.Text
>
> Error.Text may be filled but "Error" itself should be false after Return.
> Do not test Error members like Error.Text or Error.Value just test Error
>
> Can you confirm that Error itself is not False like you say.
>
>
> BruceS
>
>
>
> On Tue, 11 Nov 2025, 06:25 CD, <dessere.claude@xxxxxx> wrote:
> > Thank you for your reply.
> >
> > So, after rereading the documentation on error handling,
> >
> > I found the following at https://gambaswiki.org/wiki/lang/error:
> >
> > "The error flag is reset to FALSE when:
> >
> > The RETURN instruction is executed.
> >
> > A TRY instruction has been executed without any error."
> >
> > Therefore, if I understand correctly, in the procedure:
> >
> > Public Sub _GetRowHeight(iRow As Integer) As Integer
> >
> > Try Return $cHeight[iRow]
> >
> > Return _GetDefaultRowHeight()
> >
> > End
> >
> > the line `Try Return $cHeight[iRow]` generates an error,
> > but the line `Return _GetDefaultRowHeight()` does not reset the error flag
> > to false!
> >
> > This doesn't match the documentation!
> >
> > Personally, I will no longer test members of the `Error` class in the code
> > without first using `Try`.
> > But I'm still not entirely sure how error handling works in Gambas.
> > Perhaps more examples and explanations would be helpful.
> >
> >
> > Le lundi 10 novembre 2025 à 18:28 +0000, Bruce Steers a écrit :
> > > That is not how you check for errors.
> > > It should be done like this after a Try...
> > >
> > > If Error then
> > > Print Error.Text
> > > Endif
> > >
> > > After that Error.Text is not reset to null, it will always display the
> > > last error text.
> > >
> > > So randomly checking Error.Text or Error.Value at some time in your code
> > > will just show the last error msg/value.
> > >
> > > An Error is not something that always throws an exception.
> > >
> > > Eg..
> > > Try File.Load(sPath)
> > > If Error Then
> > > Print Error.Text
> > > Endif
> > >
> > > Error text is filled in but there was no exception to halt the program.
> > >
> > > So the only error in your form is how you are using Error.class
> > > The error you are displaying is from this code in _GridView_Rows.class
> > >
> https://gitlab.com/gambas/gambas/-/blob/master/comp/src/gb.gui.base/.src/GridView/_GridView_Rows.class?ref_type=heads
> > > Public Sub _GetRowHeight(iRow As Integer) As Integer
> > >
> > > Try Return $cHeight[iRow]
> > > Return _GetDefaultRowHeight()
> > >
> > > End
> > >
> > > It attempts
> > > Try Return $cHeight[iRow]
> > > if that fails it returns _GetDefaultRowHeight()
> > >
> > > Respects
> > > BruceS
> > >
> > >
> > > On Mon, 10 Nov 2025 at 15:47, CD <dessere.claude@xxxxxx> wrote:
> > > > Hello,
> > > >
> > > > I have an application with a main form
> > > > from which I launch another form in ShowModal mode.
> > > >
> > > > After this form is submitted, I test the Error class which returns:
> > > >
> > > > Print Error.Class -> (Class 0x590273648788)
> > > > Print Error.Code -> 6
> > > > Print Error.Text -> Type mismatch: wanted Integer, got Null instead
> > > > Print Error.Where -> [gb.gui.base]._GridView_Rows._GetRowHeight.161
> > > >
> > > > I reproduced the issue with a Test application .
> > > >
> > > > What about the error coming from
> > > > [gb.gui.base]._GridView_Rows._GetRowHeight.161 ?
> > > >
> > > > Project attached
> > > >
> > > > Regards
> > > >
> > > >
> > > >
> > > >
> > > > [System]
> > > > Gambas=3.21.0 7f84523 (master)
> > > > OperatingSystem=Linux
> > > > Distribution=Ubuntu 24.04.3 LTS (Noble Numbat)
> > > > Kernel=6.8.0-86-generic
> > > > Architecture=x86_64
> > > > Cores=8
> > > > Memory=7817M
> > > > Language=fr_FR.UTF-8
> > > > Platform=x11
> > > > Desktop=MATE
> > > > DesktopResolution=96
> > > > DesktopScale=9
> > > > WidgetTheme=blackmate
> > > > Font=Ubuntu Mono,13
> > > > DarkTheme=True
> > > > [Programs]
> > > > dpkg=Programme « dpkg » de gestion de paquets Debian version 1.22.6
> > > > (amd64).
> > > > gcc=gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
> > > > git=git version 2.43.0
> > > > msgmerge=msgmerge (GNU gettext-tools) 0.21
> > > > rpmbuild=RPM version 4.18.2
> > > > [Libraries]
> > > > Cairo=libcairo.so.2.11800.0
> > > > Curl=libcurl.so.4.8.0
> > > > DBus=libdbus-1.so.3.32.4
> > > > GDK2=libgdk-x11-2.0.so.0.2400.33
> > > > GDK3=libgdk-3.so.0.2409.32
> > > > GStreamer=libgstreamer-1.0.so.0.2402.0
> > > > GTK+2=libgtk-x11-2.0.so.0.2400.33
> > > > GTK+3=libgtk-3.so.0.2409.32
> > > > OpenGL=libGL.so.1.7.0
> > > > Poppler=libpoppler.so.134.0.0
> > > > Poppler=libpoppler.so.73.0.0
> > > > QT5=libQt5Core.so.5.15.13
> > > > QT6=libQt6Core.so.6.4.2
> > > > RSvg=librsvg-2.so.2.50.0
> > > > SDL=libSDL2-2.0.so.0.3000.0
> > > > SQLite3=libsqlite3.so.0.8.6
> > > > [Environment]
> > > > COMPIZ_CONFIG_PROFILE=mate
> > > > DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
> > > > DEBUGINFOD_URLS=https://debuginfod.ubuntu.com
> > > > DEFAULTS_PATH=/usr/share/gconf/mate.default.path
> > > > DESKTOP_SESSION=mate
> > > > DISPLAY=:0
> > > > GB_GUI=gb.gtk3
> > > > GDMSESSION=mate
> > > > GDM_LANG=fr_FR
> > > > GIO_LAUNCHED_DESKTOP_FILE=<home>/Bureau/gambas3.desktop
> > > > GIO_LAUNCHED_DESKTOP_FILE_PID=183671
> > > > GNOME_KEYRING_CONTROL=/run/user/1000/keyring
> > > > GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
> > > > GTK3_MODULES=xapp-gtk3-module
> > > > GTK_MODULES=appmenu-gtk-module:gail:atk-bridge:canberra-gtk-module
> > > > GTK_OVERLAY_SCROLLING=0
> > > > HOME=<home>
> > > > INSIDE_CAJA_PYTHON=
> > > > LANG=fr_FR.UTF-8
> > > > LANGUAGE=fr_FR.UTF-8
> > > > LC_ADDRESS=fr_FR.UTF-8
> > > > LC_IDENTIFICATION=fr_FR.UTF-8
> > > > LC_MEASUREMENT=fr_FR.UTF-8
> > > > LC_MONETARY=fr_FR.UTF-8
> > > > LC_NAME=fr_FR.UTF-8
> > > > LC_NUMERIC=fr_FR.UTF-8
> > > > LC_PAPER=fr_FR.UTF-8
> > > > LC_TELEPHONE=fr_FR.UTF-8
> > > > LC_TIME=fr_FR.UTF-8
> > > > LOGNAME=<user>
> > > > MANDATORY_PATH=/usr/share/gconf/mate.mandatory.path
> > > > MATE_DESKTOP_SESSION_ID=this-is-deprecated
> > > > PAPERSIZE=a4
> > > > PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/g
> > > > ames:/usr/local/games:/snap/bin
> > > > PWD=<home>
> > > > QT_ACCESSIBILITY=1
> > > > QT_FONT_DPI=96
> > > > QT_LOGGING_RULES=*.debug=false
> > > > QT_QPA_PLATFORMTHEME=gtk2
> > > > QT_SCALE_FACTOR=1
> > > > SESSION_MANAGER=local/<hostname>:@/tmp/.ICE-
> > > > unix/2550,unix/<hostname>:/tmp/.ICE-unix/2550
> > > > SHELL=/bin/bash
> > > > SHLVL=0
> > > > SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
> > > > TZ=:/etc/localtime
> > > > UBUNTU_MENUPROXY=1
> > > > USER=<user>
> > > > XAUTHORITY=<home>/.Xauthority
> > > > XDG_CONFIG_DIRS=/etc/xdg/xdg-mate:/etc/xdg
> > > > XDG_CURRENT_DESKTOP=MATE
> > > > XDG_DATA_DIRS=/usr/share/mate:/usr/share/mate:/usr/share/gnome:/usr/loca
> > > > l/share:/usr/share:/var/lib/snapd/desktop
> > > > XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/<user>
> > > > XDG_RUNTIME_DIR=/run/user/1000
> > > > XDG_SEAT=seat0
> > > > XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
> > > > XDG_SESSION_CLASS=user
> > > > XDG_SESSION_DESKTOP=mate
> > > > XDG_SESSION_ID=c1
> > > > XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
> > > > XDG_SESSION_TYPE=x11
> > > > XDG_VTNR=7
> > > >
> >
> >
| Re: TestError | BB <adamnt42@xxxxxxxxx> |
| TestError | CD <dessere.claude@xxxxxx> |
| Re: TestError | Bruce Steers <bsteers4@xxxxxxxxx> |
| Re: TestError | CD <dessere.claude@xxxxxx> |
| Re: TestError | Bruce Steers <bsteers4@xxxxxxxxx> |