It is currently Wed Sep 18, 2019 2:11 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject:
PostPosted: Wed Feb 27, 2002 4:50 am 
Offline
PureBasic Guru
PureBasic Guru

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

Errorhandler with parsing the errorcode
Include it in your apps for dealing with fatal errors your own way.

Code:
; ---------------------------------------------
; Examplecode for Error-Trap
; Catch Fatal Errors and handle it on your own
; Created by FAKEFACTORY
;
; Purebasic / WIN32
; ---------------------------------------------




; ---------------------------------------------
; Needed structures and constants
; ---------------------------------------------

Structure _EXCEPTION_POINTERS
    *ExceptionRecord.EXCEPTION_RECORD;
    *ContextRecord.CONTEXT;
EndStructure

#EXCEPTION_ILLEGAL_INSTRUCTION  = $C000001D
#EXCEPTION_STACK_OVERFLOW       = $C00000FD



; ---------------------------------------------
; Cleanup Procedure
; ---------------------------------------------


Procedure _Cleanup()
  Delay(1)
  ; Here your code for cleanup your allocated memory, bitmaps etc...
EndProcedure


; ---------------------------------------------
; The core of our Error-Trap
; ---------------------------------------------

Procedure _MyExceptionFilter(*ExceptionInfo._EXCEPTION_POINTERS)

 
 If TerminateInProcess.b = #TRUE
   
    ; If our own ExceptionFilter fires an error, we need to call the
    ; OS-Error-Handler for exiting
   
    Procedure_Result.l = SetUnhandledExceptionFilter_(0)
    RaiseException_ (0,0,0,0)
    End
 Else
   
    ; Get some info about the error
   
    TerminateInProcess.b = #TRUE
    ErrorCode.l = *ExceptionInfo\ExceptionRecord\ExceptionCode
    Select ErrorCode.l
        Case #EXCEPTION_FLT_DIVIDE_BY_ZERO
            Fehler$ =   "Error: DIVISION BY ZERO"
        Case #EXCEPTION_INT_DIVIDE_BY_ZERO
            Fehler$ =   "Error: DIVISION BY ZERO"
        Case #EXCEPTION_ACCESS_VIOLATION
            Fehler$ =   "Error: ACCESS VIOLATION"
        Case #EXCEPTION_ARRAY_BOUNDS_EXCEEDED
            Fehler$ =   "Error: ARRAY BOUNDS EXCEEDED"
        Case #EXCEPTION_DATATYPE_MISALIGNMENT
            Fehler$ =   "Error: DATATYPE MISALIGNMENT"
        Case #EXCEPTION_ILLEGAL_INSTRUCTION
            Fehler$ =   "Error: ILLEGALINSTRUCTION"
        Case #EXCEPTION_STACK_OVERFLOW
            Fehler$ =   "Error: STACK OVERFLOW"
        Default
            Fehler$ =  "Error: Unknown error"
    EndSelect
   
    ; Pop up a message box
   
    Titel$ = "Oops" +Chr(0)
    Fehler$ + Chr(13) + "I will now exiting the program. See 'ya"
    Procedure_Result.l = MessageBox_ (#NULL, @Fehler$, @Titel$, #MB_OK | #MB_ICONSTOP)
    _Cleanup()  : End
 EndIf
EndProcedure


; ---------------------------------------------
; MAIN PROGRAM
; ---------------------------------------------

; Activate our Errorhandler
Result.l = SetUnhandledExceptionFilter_(@_MyExceptionFilter())

If OpenWindow(0,100,100, 400, 200, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget ,"Crashtest")
   ; Now let us rise a Division by Zero for example
   IamZero.l = 0
   IwillCrash.l = 1 / IamZero.l
   
   ; The following code will never be executed :wink:
   
   Repeat
   EventID.l = WaitWindowEvent()
 
   Until EventID.l = #WM_CLOSE

 
EndIf

; Restore Errorhandler before exiting the program
Procedure_Result.l = SetUnhandledExceptionFilter_(0)
End






Registered PureBasic Coder


Edited by - FAKEFACTORY on 27 February 2002 04:54:39


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 27, 2002 6:13 am 
Offline
PureBasic Guru
PureBasic Guru

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

woah! HEAVY stuff..kool
Maybe I can figure
out how to use it too!

I'm sure I'll find a
use for it down the road....jb

elecTRONics DOCtor
{registeredPB}P150 32Mb w98/DOS/Linux NO DirX NO IE :wink:


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 27, 2002 6:38 am 
Offline
PureBasic Guru
PureBasic Guru

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

Thanks for posting the code to the PB Basement!

Shane R. Monroe, Dark Unicorn Productions
Pure Basic Basement
http://pb.darkunicornproductions.com


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Feb 28, 2002 10:35 pm 
Offline
PureBasic Guru
PureBasic Guru

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

Hi FakeFactory
Nice example... i saw it some time ago somwhere in the net as c++ example :wink: I have tested your example but seems there is a small problem...!?

Code:
[u]you wrote:[/u]
   ; The following code will never be executed :wink:
   ;
   Repeat
      EventID.l = WaitWindowEvent()
   Until EventID.l = #WM_CLOSE


Mhhh... i get your requester but seems that the following lines will be executed on my system too...!?

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Feb 28, 2002 11:12 pm 
Offline
PureBasic Guru
PureBasic Guru

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

Huh?

Your program continues *after* a division by zero???
Wow, we should swap the computers.

;)

don't know, how this can happen. Have you any anti-crash soft like CrashProf installed.

Registered PureBasic Coder


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 01, 2002 12:25 am 
Offline
PureBasic Guru
PureBasic Guru

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

Quote:
FakeFactory wrote:
Your program continues *after* a division by zero???
Wow, we should swap the computers. :wink:


Hi FakeFactory
hehe... yes, the program will still continue executing all next operations..

Quote:
don't know, how this can happen. Have you any anti-crash soft like CrashProf installed.


Sorry, i dont know too... i dont have any patched/hacked system related stuff... just a normal Win98 system... strange!


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 01, 2002 1:25 am 
Offline
PureBasic Guru
PureBasic Guru

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

> Your program continues *after* a division by zero???

I doubt it. Obviously the error handler catches it BEFORE it occurs, and
then reports the error via the API.


PB - Registered PureBasic Coder


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 18 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