It is currently Sun Feb 28, 2021 4:57 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Example of an Error Handler by FAKEFACTORY
PostPosted: Thu Jan 17, 2002 5:07 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Code updated For 5.20+

Restored from previous forum. Originally posted by Franco.

Code:
; Found this great peace of code on the german PureBasic forum.
; Coded by FakeFactory, translated from german to english by Franco.
; Well documented example of the implementation of an Error-Trap-Routine
;
; You can add some code to receive information about what caused the error. (if you need...)
; For this look at MSDN or in a good C++ for Windows book.
 
Structure _EXCEPTION_POINTERS
  *ExceptionRecord.EXCEPTION_RECORD;
  *ContextRecord.CONTEXT;
EndStructure
 
Procedure _MyExceptionFilter(*lpEP._EXCEPTION_POINTERS)
  ; This is your own Error Message Handler.
  ; If your program is causing an illegal operation you get a crash and a Windows message like:
  ; "This program has performed an illegal operation and will be shut down"
  ; But with this Procedure not anymore!
  ; Now you get your own MessageBox and the Program will be ended smoothly.
  ; The user will be delighted and the bug in YOUR code seems to be not so bad at all.
 
  Shared TerminateInProcess.b

  If TerminateInProcess.b = #TRUE

    ; Well if you reach this point there was an error in our own Error Message Handler.
    ; We are not able to end our program smoothly.
    ; In this case we can do nothing and the Operating System has to do the work...
    ; But first we have to close our own Error Message Handler.
 
    Result.l = SetUnhandledExceptionFilter_(0)

    ; And now we get a nice crash controlled by the Operating System

    RaiseException_ (0,0,0,0)

    End
  Else
    TerminateInProcess.b = #TRUE
    ; OK we have now full control over the nasty bug and
    ; send a nice death announcement of the program...

    hWnd.l = WindowID(0)
    Result.l = MessageBox_ (hWnd.l, "We truly apologize for this inconvenience.", "Ups... there was a problem.", #MB_OK | #MB_ICONSTOP)
    End
  EndIf
EndProcedure
 
; this point is the normal start of your code and we have to activate the Error Handler
Result.l = SetUnhandledExceptionFilter_(@_MyExceptionFilter())
 
; start of your code
; yada, yada, yada...
 
; this point is the normal end of your code and we have to deactivate the Error Handler
Result.l = SetUnhandledExceptionFilter_(0)


Have a nice day...
Franco

BTW I didn't change the code above. But it's working without declaring the structure and without *lpEP._EXCEPTION_POINTERS when you call the procedure, it's not used inside the procedure anyway...


Edited by - franco on 17 January 2002 17:54:15


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 17, 2002 6:27 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by FAKEFACTORY.

You need the structure, if you want to parse the error and give some details on the error.



Registered PureBasic Coder


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye