Other code examples |
Overview |
Painter package |
|
HTML widget |
|
Scrollbar / slider widget |
|
Sub button1_clicked() |
Progressbar widget |
Sub button1_clicked() |
Datetime package |
Dim d As date |
Standard dialog package |
filedialog |
Component to create QFileDialog widget |
fontdialog |
Component to create QFontDialog widget |
colordialog |
Component to create QColorDialog widget |
printdialog |
Component to create QPrintDialog widget |
Dim f As filedialog |
File package |
FILE |
Read and write access to files (see example) |
FILEDLG |
Call QFileDialog to ask user for filename |
FILEINFO |
Get Info about files (QFileInfo) |
DIRINFO |
Get Info about directory structures and their
contents (QDirInfo) |
|
Menu example |
|
Debugging |
Project Project1 |
Error handling |
Sub button1_clicked()
For While
End Sub
When you start the compiler for this example you can see how HBasic shows error messages at compile time.
Runtime exceptions |
The next example forces a runtime error because of an overflow in an integer variable.
Project Project1 |
Caught runtime exception |
If you don't want your program to stop with an emergency exit any time a runtime error occures you can use a "try .. catch .. end try" structure to catch the runtime error.
Public small As Short |
There is no need for the "Try ... Catch" structure to be in the same subroutine where the runtime error occures. If there is no runtime handler in the current subroutine HBasic continues to search for a "Try...Catch" structure in the calling subroutine.
Example to show fallback to calling subroutine for runtime error handling.
Dim i As Short
Sub button1_clicked()
i = 1111
Try
test2()
Catch( IntegerOverflov )
Print "Overflow error ..."
End Try
End Sub