Overview Go provides a built-in function recover for recovering from a panic. Below is the signature of this function defer function is the only function that is called after the panic. So…
Tag: go
How to create panic in Go (Golang)
Overview Panic is similar to the exception in golang. Panic is meant to exit from a program in abnormal conditions. Panic can occur in a program in two ways Runtime error in…
Panic stack trace in Go (Golang)
Overview debug package of golang provides a StackTrace function that can be used print the stack trace of the panic in the recover function Example Let’s see a program for that Output In…
Format a message without printing in Go (Golang)
Overview Sprintf function of fmt package can be used to format the string without printing it. It is similar to Printf function with the only difference between the two being Printf formats…
Recover function return value in Go (Golang)
Overview The recover function returns the value which was passed to the panic function. Therefore it is a good practice to check the return value of the recover function. If the return value is…
Return value of the function when panic is recovered in Go (Golang)
Overview When the panic is recovered then the return value of a panicking function will be the default value of the return types of the panicking function Program Let’s see a program for…
Panic and Recover in Go (Golang)
This is the chapter 28 and also the last chapter of the golang comprehensive tutorial series. This is Refer to this link for other chapters of the series – Golang Comprehensive Tutorial Series…
Recover panic from goroutine in Go (Golang)
Overview There are two cases for recovering from a panic in a goroutine recover function in the same goroutine as panic recover function in a different goroutine as panic While in the…
Panic format string in Go (Golang)
Overview Below is the syntax of the panic function It takes empty interface as an argument. It does not provides any why to format the error string. However there is a workaround….
Defer a goroutine in Go (Golang)
Overview It is not directly possible to defer a goroutine. But there is a workaround. In the defer function you can call another function in a goroutine like below Example Let’s see…