Displaying your own debugger errors

Just starting out? Need help? Post your questions and find answers here.
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post by #NULL »

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
  
  ; [...]
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Crap #NULL got there first! 8) Good Job #Null...

As an aside... you might also try the MessageRequester to generate a popup... :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

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).
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

Thanks for the quick answers guys! :D

Kind regards,

Francis.
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post by #NULL »

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.

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"
Post Reply