Error (the Class) vs ERROR (the Boolean)
Posted
#1
(In Topic #327)
Regular

_______________
Code
' Gambas module file
Public Sub Main()
Print "Hello world"
Print 1 / 0
Catch
' Debug Error.Text 'OK
Debug FormatError( Error ) 'NOT OK: not using ByRef; 'wanted Error got Boolean'
'Debug FormatError(ByRef Error ) 'NOT OK: using ByRef; 'this expression cannot be passed by reference'
End
Public Function FormatError(oError As Error) As String
Dim sResult As String = Null
sResult &= oError.Text & gb.CrLf & Error.Class & gb.CrLf & Error.Where & gb.CrLf & Error.Backtrace
Return sResult
End
Posted
Regular

Code
' Gambas module file
Public Sub Main()
Print "Hello world"
Print 1 / 0
Catch
Debug FormatError(Error.Text, Error.Class, Error.Where, Error.Backtrace) 'NOT OK: FormatError not using ByRef; wanted Error got Boolean
End
Public Function FormatError(sText As String, sClass As String, sWhere As String, sBacktrace As String) As String
Dim sResult As String = Null
sResult &= sText & gb.CrLf & sClass & gb.CrLf & sWhere & gb.CrLf & sBacktrace
Return sResult
End
Posted
Regular

[System]
Gambas=3.14
OperatingSystem=Linux
Kernel=4.15.0-65-generic
Architecture=x86_64
Distribution=Linux Mint 19.2 Tina
Desktop=CINNAMON
Theme=Qt5CTProxy
Language=en_US.UTF-8
Memory=7917M
[Libraries]
Cairo=libcairo.so.2.11510.0
Curl=libcurl.so.4.5.0
DBus=libdbus-1.so.3.19.4
GStreamer=libgstreamer-1.0.so.0.1405.0
GTK+2=libgtk-x11-2.0.so.0.2400.32
GTK+3=libgtk-3.so.0.2200.30
OpenGL=libGL.so.1.0.0
Poppler=libpoppler.so.73.0.0
QT4=libQtCore.so.4.8.7
QT5=libQt5Core.so.5.9.5
SDL=libSDL-1.2.so.0.11.4
SQLite=libsqlite3.so.0.8.6
[Environment]
CINNAMON_VERSION=4.2.4
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DEFAULTS_PATH=/usr/share/gconf/cinnamon.default.path
DESKTOP_SESSION=cinnamon
DISPLAY=:0
GB_GUI=gb.qt5
GDMSESSION=cinnamon
GDM_LANG=en_US
GIO_LAUNCHED_DESKTOP_FILE=/usr/share/applications/gambas3.desktop
GIO_LAUNCHED_DESKTOP_FILE_PID=30177
GJS_DEBUG_OUTPUT=stderr
GJS_DEBUG_TOPICS=JS ERROR;JS LOG
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
GTK_MODULES=gail:atk-bridge
GTK_OVERLAY_SCROLLING=1
HOME=<home>
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LOGNAME=<user>
MANDATORY_PATH=/usr/share/gconf/cinnamon.mandatory.path
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:<home>/.dotnet/tools
PWD=<home>
QT_ACCESSIBILITY=1
QT_QPA_PLATFORMTHEME=qt5ct
SESSION_MANAGER=local/<hostname>
SHELL=/bin/bash
SHLVL=0
SSH_AGENT_PID=2154
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
S_COLORS=auto
TZ=:/etc/localtime
USER=<user>
XAUTHORITY=<home>/.Xauthority
XDG_CONFIG_DIRS=/etc/xdg/xdg-cinnamon:/etc/xdg
XDG_CURRENT_DESKTOP=X-Cinnamon
XDG_DATA_DIRS=/usr/share/cinnamon:/usr/share/gnome:<home>/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
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_DESKTOP=cinnamon
XDG_SESSION_ID=c2
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SESSION_TYPE=x11
XDG_VTNR=7
Posted
Administrator

There is no need to pass Error (the class) as you can approach it directly.
Try this:
Code (gambas)
- sResult &= "Backtrace:\n"
- sResult &= sLine & "\n"
- Return sResult
Take into account that:
- Error.Class returns a class NOT a string and will give you an error (Type mismatch: wanted String, got Class instead) if trying to get it returned as a string.
- Error.Backtrace will return an array of strings and will give an error if trying to get it returned in your string result.
Hope this short example will help you.
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Regular

I definitely overlooked the types on Class and Backtrace – I have to look more carefully.
Steve
Posted
Regular

Posted
Administrator

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Regular

1 guest and 0 members have just viewed this.


