It is currently Tue Nov 12, 2019 12:26 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 4:30 pm 
Offline
User
User

Joined: Wed Jul 17, 2019 5:32 pm
Posts: 39
"Let me know when this app reports back."

I'm not sure what your issue is. The function returns the value (404) to the calling procedure while allowing me to acquire the error number via ErrorCode() and the error message via ErrorMessage(). Exactly what I wanted it to do.

Some people just work so hard at making issues more difficult than they need to be.


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 4:51 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 558
skywalk wrote:
Let me know when this app reports back. :lol:


Width rsp it should work ;)


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 6:28 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3109
Location: Boston, MA
Nice try, but Fails with threadsafe.
Dawgmann wrote:
Some people just work so hard at making issues more difficult than they need to be.
Sorry if my "toy" apps are a problem.
Code:
; Mijikai, https://www.purebasic.fr/english/viewtopic.php?f=3&t=73592&start=15
; COMPILER OPTIONS:
;   [ ] Main source file:
;   [ ] Use Compiler:   PureBasic 5.71 (Windows - x64)
;   [ ] Use Icon:       
;   [ ] Enable inline ASM syntax coloring
;   [x] Create threadsafe executable
;   [x] Enable OnError lines support
;   [x] Enable modern theme support (for Windows XP and above)
;   [ ] Request Administrator mode for Windows Vista and above
;   [ ] Request User mode for Windows Vista (no virtualisation)
;   [ ] Enable DPI aware executable (Windows)
;   Library Subsystem:
;   Executable format:        Windows ;|Console|Shared DLL
;   CPU Optimisation:         All     ;|Dynamic|w/MMX|w/3DNOW|w/SSE|w/SSE2
;   Sourcefile Text encoding: UTF-8
; COMPILE/RUN:
;   [x] Create temporary executable in the source directory
; CONSTANTS:
; VERSION INFO/RESOURCES:
;   Update version info in:   auto set fields --> %yy.%mm.%dd OR C:\dev\some-resource.rc
; IDE PREFERENCES:ToolsPanel:Configuration:Procedure Browser
;   [x] Sort Procedures by name       ;<-- Alphabetical instead of order of appearance. Uncheck when location of Proc desired.
;   [ ] Group Markers                 ;<-- If checked, ';-!' priority listing is lost.
;   [ ] Display Procedure Arguments   ;<-- Too busy if checked.
#mysmall1 = 1e-2
Macro OnErrorResume(Label)
  !push rax rcx rdx rbx rbp rsi rdi rsp
  OnErrorGoto(Label)
EndMacro
Procedure End_Graceful()
  MessageRequester("End Graceful", ErrorMessage(ErrorCode()))
EndProcedure
Procedure.i Dummy(Something.i)
  OnErrorResume(?ErrorHandler)
  Protected.i x,y
  x = 1 / (y + #mysmall1)   ; FAIL
  ProcedureReturn Something
  ErrorHandler:
  End_Graceful()
EndProcedure
MessageRequester(#Null$, Str(Dummy(123)))

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 6:45 pm 
Offline
User
User

Joined: Wed Jul 17, 2019 5:32 pm
Posts: 39
Yeah...

I don't care if it fails on Threadsafe. I don't care if it fails when dividing by zero. I don't care if it fails when unicorns duck behind a tree to take a poop.

I need it for what I do. The fact you can't comprehend that after all my posts saying so, and after all this time, well... that kind of eludes to possible mental issues and your Trump-like need to feel like your correct.


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 7:00 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 558
@skywalk
Code:
Macro OnErrorResume(Label)
  !push rax rcx rdx rbx rbp rsi rdi rsp r8 r9 r10 r11 r12
  OnErrorGoto(Label)
EndMacro


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 7:08 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3109
Location: Boston, MA
Dawgmann wrote:
Yeah...

I don't care if it fails on Threadsafe. I don't care if it fails when dividing by zero. I don't care if it fails when unicorns duck behind a tree to take a poop.

I need it for what I do. The fact you can't comprehend that after all my posts saying so, and after all this time, well... that kind of eludes to possible mental issues and your Trump-like need to feel like your correct.
You continue to disparage those trying to help you? You said you MUST capture unintended errors and exit gracefully. Yet, now you say, some errors are ok to crash away. I only show divide by zero because it is a simple case. My apps are always threaded, so I showed that too. There are many other error types like stepping beyond array limits or null pointers and so on. By all means, shout me down for Trump-like help.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 7:13 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3109
Location: Boston, MA
Mijikai wrote:
@skywalk
Code:
Macro OnErrorResume(Label)
  !push rax rcx rdx rbx rbp rsi rdi rsp r8 r9 r10 r11 r12
  OnErrorGoto(Label)
EndMacro
Sorry, this immediately triggers an error even with divide by zero commented out :shock:

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 7:40 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 558
skywalk wrote:
Mijikai wrote:
@skywalk
Code:
Macro OnErrorResume(Label)
  !push rax rcx rdx rbx rbp rsi rdi rsp r8 r9 r10 r11 r12
  OnErrorGoto(Label)
EndMacro
Sorry, this immediately triggers an error even with divide by zero commented out :shock:


True i need to look into it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 7:49 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 558
I assume we just need to modify the return address:

Code:
Macro OnErrorResume(Label)
  OnErrorGoto(Label)
EndMacro

Procedure End_Graceful()
  MessageRequester("End Graceful", ErrorMessage(ErrorCode()))
EndProcedure

Procedure.i Dummy(Something.i)
  OnErrorResume(?ErrorHandler)
  Protected.i x,y
  PokeS(10, "Hello World")
  ProcedureReturn Something
  ErrorHandler:
  !push rax rcx rdx rbx rsi rdi r8 r9;<- this works also here
 
  End_Graceful();<- this jumps back to the old code
 
  ;if we figure out how to patch the return address everything will work i guess
 
  ProcedureReturn 444
EndProcedure
MessageRequester(#Null$, Str(Dummy(123)))


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Thu Sep 12, 2019 8:03 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3109
Location: Boston, MA
Yes, this is to avoid having the same End_Graceful() code within every procedure using OnErrorResume(). :(

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Fri Sep 13, 2019 10:13 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 558
Its probably better to build it from scratch.

Something like this: https://www.codeproject.com/articles/17263/moving-to-windows-vista-x64

Quote:
Remember the old days when you set the SEH in your code?
Well, with x64/Itanium they're gone.
Exception Handlers are now stored as structured in the PE64 Exception Directory.


Quote:
If you need to generate code dynamically and set for it an exception handler, you can use the function RtlAddFunctionTable, which takes as parameter an array of RUNTIME_FUNCTION structures. This means, of course, that you'll have to fill one or more UNWIND_INFO structure/s by yourself.


Other links:
https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019
http://www.osronline.com/article.cfm%5earticle=469.htm
https://stackoverflow.com/questions/28549775/seh-handlers-using-rtladdfunctiontable

Some (hopefully) translated structs:
Code:
EnableExplicit

Enumeration UNWIND_OP_CODES
  #UWOP_PUSH_NONVOL = 0 ;info == register number
  #UWOP_ALLOC_LARGE     ;no info, alloc size in Next 2 slots
  #UWOP_ALLOC_SMALL     ;info == size of allocation / 8 - 1
  #UWOP_SET_FPREG       ;no info, FP = RSP + UNWIND_INFO.FPRegOffset*16
  #UWOP_SAVE_NONVOL     ;info == register number, offset in Next slot
  #UWOP_SAVE_NONVOL_FAR ;info == register number, offset in Next 2 slots
  #UWOP_SAVE_XMM128 = 8 ;info == XMM reg number, offset in next slot
  #UWOP_SAVE_XMM128_FAR ;info == XMM reg number, offset in next 2 slots
  #UWOP_PUSH_MACHFRAME  ;info == 0: no error-code, 1: error-code
EndEnumeration

#UNW_FLAG_EHANDLER = $1
#UNW_FLAG_UHANDLER = $2
#UNW_FLAG_CHAININFO = $4

Structure RUNTIME_FUNCTION Align 4
  BeginAddress.l
  EndAddress.l
  UnwindData.l
EndStructure

Structure UNWIND_CODE_INFO
  CodeOffset.a
  UnwindOp.a[4]
  OpInfo.a[4]
EndStructure

Structure UNWIND_CODE
  StructureUnion
    Info.UNWIND_CODE_INFO
    FrameOffset.u
  EndStructureUnion
EndStructure

Structure UNWIND_INFO Align 4
  Version.a[3]
  Flags.a[5]
  SizeOgProlog.a
  CountOfCodes.a
  FrameRegister.a[4]
  FrameOffset.a[4]
  UnwindCode.UNWIND_CODE[0]
EndStructure

;-> https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019
;-> On runtime we could use: RtlAddFunctionTable_()


Im not sure how to actually do it yet, so unless someone wants to help with this
i rather invest my time in something different.


Top
 Profile  
Reply with quote  
 Post subject: Re: Try/Catch/Finally error handling...
PostPosted: Fri Sep 13, 2019 3:00 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3109
Location: Boston, MA
Good find. I am buried too. This could go in feature requests but it is Windows only. :(

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3

All times are UTC + 1 hour


Who is online

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