Thanks for answering. Basically I found a work around.
As I said, I understand go handles error differently, but imagine my windows OS send an exception signal not handled by go, how to handle this ? Escpecially given I don;'t just want the default Go handler that print the stack with the exception code and registers then exit the program ...
By default, in the Go runtime you indeed use the AddVectoredExceptionHandler windows API (which is why it is imported by Kernel32.dll in the Import Address Table and linked to the Go binary).
However you use just a set of exception and not everything :D
Correct me If I am wrong but from what I saw in `signal_windows.go`:
```
case _EXCEPTION_ACCESS_VIOLATION:
case _EXCEPTION_IN_PAGE_ERROR:
case _EXCEPTION_INT_DIVIDE_BY_ZERO:
case _EXCEPTION_INT_OVERFLOW:
case _EXCEPTION_FLT_DENORMAL_OPERAND:
case _EXCEPTION_FLT_DIVIDE_BY_ZERO:
case _EXCEPTION_FLT_INEXACT_RESULT:
case _EXCEPTION_FLT_OVERFLOW:
case _EXCEPTION_FLT_UNDERFLOW:
case _EXCEPTION_BREAKPOINT:
case _EXCEPTION_ILLEGAL_INSTRUCTION: // breakpoint arrives this way on arm64
```
You only treat these exceptions in `isgoexception` function.
I changed `isgoexception` to:
```
func isgoexception(info *exceptionrecord, r *context) bool {
switch info.exceptioncode {
default:
return false
case _EXCEPTION_ACCESS_VIOLATION:
case _EXCEPTION_IN_PAGE_ERROR:
case _EXCEPTION_INT_DIVIDE_BY_ZERO:
case _EXCEPTION_INT_OVERFLOW:
case _EXCEPTION_FLT_DENORMAL_OPERAND:
case _EXCEPTION_FLT_DIVIDE_BY_ZERO:
case _EXCEPTION_FLT_INEXACT_RESULT:
case _EXCEPTION_FLT_OVERFLOW:
case _EXCEPTION_FLT_UNDERFLOW:
case _EXCEPTION_BREAKPOINT:
case 0xE0000001: // HERE I added this and changed order
case _EXCEPTION_ILLEGAL_INSTRUCTION: // breakpoint arrives this way on arm64
}
return true
if r.ip() < firstmoduledata.text || firstmoduledata.etext < r.ip() {
println("In Weird Stuff")
return false
}
return true
}
```
And basically I can now handle my Exception Signal.
```
func myHandler(exceptionInfo *handler.EXCEPTION_POINTERS) uintptr {
println("Exception occurred! ---> Code")
println(exceptionInfo.ExceptionRecord.ExceptionCode)
println("Life happens, lets continue")
// kernel32 := windows.NewLazySystemDLL("kernel32.dll")
// exitt := kernel32.NewProc("ExitThread")
// exitt.Call(uintptr(0))
return uintptr(handler.EXCEPTION_CONTINUE_EXECUTION)
}
func main() {
handler.AddVEH(myHandler)
raiseCustomException()
println("Continued")
}
```
I get what I want when I run the exe:
```
Added VEH
Exception occurred! ---> Code
3758096385
Life happens, lets continue
Continued
```
I still not fully understand how you handle AddVectoredExceptionHandler in the go runtime and why Go decided not to let the user handle their signal ... (as you see it seems easy, escepcially when the signal is exterior to the go runtime)
PS: Don't take this the wrong way, but I hope "Generative AI is experimental" will stay experimental ...