Error handling in Basic4PPC

TWELVE

Active Member
Licensed User
Hello,

i want prevent users from getting error message boxes, that contain cryptic error messages or even such with no error description.Therefore i tried a bit with the B4P error handler.This is working, if it's been triggered i still do not know what the exact error was and therefore cannot take the appropriate measure to continue.All i then can assume is: in this sub an error has occured.

Question: is there a chance to get the error description the error popup is presenting to the user..? if not, how do you handle errors in your code and how do you catch them..?

In certain other dialects i used to use a structure like this:

if function(arguments)
...
do something that depends on function
...
Else
...
do some corrective code here
MsgBox("file cannot be opened !")
end if

Why do B4P functions or routines not give back a return code of true or false..? Or do they..? My own created do and can be handled like outlined, by use of the Return directive.

Any other ways or suggestion how to handle that effectively..?



kind regards

TWELVE
 

Cableguy

Expert
Licensed User
Longtime User
Error handling in B4PPC is done using the Errorlabel method...
Taken from the B4PPC Helper:

Sets a label that the program will jump to in case an error will occur in the current sub,
Syntax: ErrorLabel (Label)
Example:
Sub OpenFile
ErrorLabel (errHandler)
FileOpen (c,"data.dat",cRead)
Return
ErrHandler:
Msgbox("Can't open file.")
End Sub

Since the Error code or description seem to be "intalation" dependant, (it seems that we need to actually install the errorcode reference file....) there is not currently available way to trap specific errors, but we can do some fancy coding and cascade a series of errorlabels, to try to catch an error at a specific code line or block...
 

agraham

Expert
Licensed User
Longtime User
Why do B4P functions or routines not give back a return code of true or false..?
This is a deliberarate design feature of the CLR. Errors are handled by throwing exceptions and catching them by error-handling code, similar to C++. Every B4PPC Sub actually has an exception handler, it is this which puts up the message box when an error occurs. Using Errorlabel replaces this default handler with your own code. Unfortunately, at the moment, there is no way to detect which exception has occurred.

Recently I made a suggestion to Erel about this and he has agreed to put a facility in the next release of B4PPC which will provide low-level access to the exception details. In anticipation I have the library and help file/tutorial ready. :cool:
 

mamuen

Member
Licensed User
Hello TWELVE,

Why do B4P functions or routines not give back a return code of true or false..? Or do they..? My own created do and can be handled like outlined, by use of the Return directive.
TWELVE

There are no functions in Basic4ppc but instead every sub can return a value
with the keyword "Return"

Sub Mean (a,b)
Return (a+b)/2
End Sub

Greatings mamuen
 

yildi

Member
Licensed User
Recently I made a suggestion to Erel about this and he has agreed to put a facility in the next release of B4PPC which will provide low-level access to the exception details. In anticipation I have the library and help file/tutorial ready. :cool:

You are really amazing agraham! :sign0098:

Murat
 
Top