I am trying to get my head wrapped around error handling again, and more explicitly the RaiseException Api call.
(Unless I am missing a Raise Error type call like back in VB)
what I am having trouble with is when I raise an exception, no matter what exception flags I use, my computer comes back with the typical has to close box.
and for the most part all examples I have found do the same, and I am totally lost at the docs as in what I thought passing a flag of continue execution is being ignored??
Below is some test code I am working on, but not sure where I am going wrong???
Even passing any error number and a flag of %SLE_MINORERROR (which should allow continuance) causes the same symptoms.
Does anyone have some code that better explains how the docs explain (cryptically) should actually behave without the zeros for parameters????
(Unless I am missing a Raise Error type call like back in VB)
what I am having trouble with is when I raise an exception, no matter what exception flags I use, my computer comes back with the typical has to close box.
and for the most part all examples I have found do the same, and I am totally lost at the docs as in what I thought passing a flag of continue execution is being ignored??
Below is some test code I am working on, but not sure where I am going wrong???
Code:
'#DEBUG ERROR ON #COMPILE EXE #DIM ALL #INCLUDE "Win32Api.inc" FUNCTION PBMAIN () AS LONG ON ERROR GOTO ErrHandler 'If error rasied then jumps to error handler LOCAL ForceCodeContinue AS LONG ForceCodeContinue = %TRUE ERROR 5 'Set Error Code (Error is raised, jump to error handler) MSGBOX "Continued from raised error" 'Results ERR = 5 'Set Error Code (Error is not raised) MSGBOX "Continued again, but no error raised" 'Results ForceCodeContinue = %FALSE '*** Use 'SetLastError' if flags are not used, but use 'SetLastErrorEx' if wanting extra info SetLastErrorEx(5, %SLE_MINORERROR) 'Invalid data was passed to the function, but the function has recovered. RaiseException 5, BYVAL %SLE_MINORERROR, BYVAL %NULL, BYVAL %NULL 'Bogus Fatal Error for Demo (or not fatal since I have control) MSGBOX "Error (Minor, code continues)" SetLastErrorEx(5, %SLE_WARNING) 'Potentially invalid data was passed to the function, but the function has recovered. MSGBOX "Error (Warning, code continues)" SetLastErrorEx(5, 0) 'The last-error code is set without reporting anything to the debugger. Specifying this value is equivalent to using the SetLastError function. MSGBOX "Error (Nothing reported to debugger)" '*** This last one must be last or your tests will result in the typical error of "*.Exe Has Stopped Working" no matter what the error number is SetLastErrorEx(5, %SLE_ERROR) 'Invalid data was passed to the function, and complete failure has occurred. RaiseException 42, %NULL, %NULL, %NULL 'Bogus Fatal Error for Demo (or not fatal since I have control) MSGBOX "Error (Major, and can not continue)" EXIT FUNCTION 'Exit to not execute error handler ErrHandler: MSGBOX "Error was raised" 'Error raised SELECT CASE ErrorHandling(ERR, ForceCodeContinue) CASE %FALSE CASE %TRUE RESUME NEXT END SELECT END FUNCTION FUNCTION ErrorHandling(ErrorNumber AS LONG, ForceCodeContinue AS LONG) AS LONG MSGBOX "Error Handled" SELECT CASE ForceCodeContinue CASE %FALSE FUNCTION = %FALSE CASE %TRUE FUNCTION = %TRUE CASE ELSE FUNCTION = %TRUE END SELECT END FUNCTION
Does anyone have some code that better explains how the docs explain (cryptically) should actually behave without the zeros for parameters????
Comment