You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
startServer()
}
func startServer() {
mainchan := make(chan struct{})
go func(ch chan<- struct{}) {
defer func() {
if r := recover(); r != nil {
fmt.Println("recovered from crash\n", r)
ch <- struct{}{}
}
}()
http.HandleFunc("/divide", func(w http.ResponseWriter, req *http.Request) {
go panic("this is to be catched")
fmt.Fprintf(w, "Hello, \nyour question is submitted\t")
})
log.Fatal(http.ListenAndServe(":8081", nil))
}(mainchan)
<-mainchan
fmt.Println("safe landing")
}
What did you expect to see?
safe landing
What did you see instead?
panic: this is to be catched
goroutine 7 [running]:
panic(0x1242be0, 0xc000012060)
/usr/local/go/src/runtime/panic.go:1065 +0x565
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1371 +0x1
created by main.startServer.func1.2
/Users/vajahatk/work/test/main.go:29 +0x1e5
exit status 2
The text was updated successfully, but these errors were encountered:
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
safe landing
What did you see instead?
The text was updated successfully, but these errors were encountered: