[Gambas-user] Custom error class

Benoît Minisini gambas at ...1...
Wed Dec 16 21:27:58 CET 2009


> Hi all
> 
> Perhaps this is an stupid question, but I'm confused at this point:
> 
> I'm trying to implement a custom error message window with information
> about an error raised within a CATCH clause, using the Error class from
> Gambas. Here is the code I'm not able to get it working:
> 
> _The error form 'FError'_
> 
> PRIVATE $error AS String
> 
> PUBLIC SUB Form_Open()
>     ME.Center
>     txtError.Clear
>     txtError.Text = $error
> END
> 
> PUBLIC SUB showError(myError AS Error)
>     $error &= "[Error]\n" & myError.Text
>     $error &= "\n[Where]\n" & myError.Where
>     $error &= "\n[Backtrace]\n" & myError.Backtrace
>     ME.ShowModal
> END
> 
> PUBLIC SUB btnOk_Click()
>     IF chkReport THEN
>     ' TODO report error to a remote db
>     ENDIF
>     ME.Close
> END
> 
> _Calling in a sub after CATCH_
> 
> CATCH
>     FEerror.showError(Error)
> 
> -----
> 
> First of all, it is not possible to write "Error" keyword between the
> two parenthesis, being formatted into "ERROR", syntactically wrong.
> 
> If I enclose the 'Error' keyword between curly brackets, as in
> FErrors.showError({Error}) , no syntax error is raised, but a Gambas
> error saying "Type mismatch: wanted Error, got Class instead".
> 
> What am I doing wrong, or is it possible to use this class the way I'm
> doing?
> 
> Help appreciated!
> 
> Regards,
> 
> Jesús
> 

At the moment Error is a static class, you cannot instanciate it, and using it 
as a datatype is uselss. So don't use an argument, use the Error class 
everywhere.

The caveats of this design is that should save or use the Error class contents 
as soon as possible, otherwise another error or a function call may reset it.

Regards,

-- 
Benoît Minisini




More information about the User mailing list