Hi there,
Is there any way to get the PureBasic debugger to display custom errors?
For example say I have written a library of procedures where you need to initialise it with a InitMyLib(). If this InitMyLib() is missing from the code and one of the functions that require it has been called can I get the dubugger to display an error along the lines of "InitMyLib() needs to be called first".
Kind regards,
Francis.
Displaying your own debugger errors
- Dreamland Fantasy
- Enthusiast
- Posts: 335
- Joined: Fri Jun 11, 2004 9:35 pm
- Location: Glasgow, UK
- Contact:
that's how i do it currently:
Code: Select all
CompilerIf #PB_Compiler_Debugger
Import "Debugger.lib"
PB_DEBUGGER_SendError(error.s)
EndImport
Macro sgxERROR(_message_)
PB_DEBUGGER_SendError("sgx ERROR: "+_message_)
EndMacro
; [...]
- Rook Zimbabwe
- Addict
- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
If your library is tailbiten, you may use TB_DebugError() like this :
Code: Select all
ProcedureDLL MyDiv(a, b)
ProcedureReturn a/b
EndProcedure
ProcedureCDLL MyDiv_DEBUG(a, b)
If b=0
TB_DebugError("Division by zero!")
EndIf
EndProcedure
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
- Dreamland Fantasy
- Enthusiast
- Posts: 335
- Joined: Fri Jun 11, 2004 9:35 pm
- Location: Glasgow, UK
- Contact:
it's very usefull.
for example you can encapsulate a *structure-array in macros to perform boundary-checks, or other things you need to verify, and to send debugger errors if necessary.
i.e. in my case here i filter invalid indices to index=0 (though the debugger stops anyway) which uses as a empty dummy element.
for example you can encapsulate a *structure-array in macros to perform boundary-checks, or other things you need to verify, and to send debugger errors if necessary.
i.e. in my case here i filter invalid indices to index=0 (though the debugger stops anyway) which uses as a empty dummy element.
Code: Select all
;{ ---------------- MACRO: sgx()
CompilerIf #PB_Compiler_Debugger
Import "Debugger.lib"
PB_DEBUGGER_SendError(error.s)
EndImport
Macro sgxERROR(_message_)
PB_DEBUGGER_SendError("sgx ERROR: "+_message_)
EndMacro
Macro sgx_debugger_check_array_bounds(index)
index * bool( ((index>=0) And (index<=sgx_CURRENT_MAX_DYNAMIC_GADGETS)) Or sgxERROR("array out of bounds: sgx("+Str(index)+")") )
EndMacro
; ****************************
Macro sgx(index)
*sgxID(sgx_debugger_check_array_bounds(index))
EndMacro
; ****************************
; ----------------
CompilerElse
Macro sgxERROR(_message_)
; <empty>
EndMacro
; ****************************
Macro sgx(index)
*sgxID(index)
EndMacro
; ****************************
CompilerEndIf ;}
; ----------------
Code: Select all
; the actual array is: Dim *sgxID.<structure>(..)
; boundary check if debugger enabled
sgx(id)\text = "bla"