Turtle
Turtle

Reputation: 31

capture panic into string variable

I have an unusual request. I need a way to convert the panic that I captured to string so I can save it. I have captured panic with recover() but it can't be converted to string because it is an interface that is runtime.boundError type. Does anyone know how can I save panics into string var for future use?

Upvotes: 1

Views: 449

Answers (1)

Mahdi zarepoor
Mahdi zarepoor

Reputation: 410

I think you can use type assertion . using type assertion you can check if an interface (in this case runtime.BoundError as you said) is of a specific type . and it is generally used to make sure that an interface value satisfies another interface or to find the concrete type of the interface.

check this playground . you can assert it into string type . https://go.dev/play/p/b6EtGrh0gGj

Upvotes: 1

Related Questions