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.
Generally I don't think it is good practice to panic in a library. Doing this assumes a number of things about the caller of the library:
They have a panic handler
OR they want their application to crash if this lib doesn't work
I am not sure we should make these assumptions. In a situation where an error occurs I believe the lib should hand back control to the caller and allow it to decide what to do in that situation as the caller has the full context and domain knowledge.
The text was updated successfully, but these errors were encountered:
Recover is a built-in function that regains control of a panicking goroutine. Recover is only useful inside deferred functions. During normal execution, a call to recover will return nil and have no other effect. If the current goroutine is panicking, a call to recover will capture the value given to panic and resume normal execution.
For a real-world example of panic and recover, see the json package from the Go standard library. It decodes JSON-encoded data with a set of recursive functions. When malformed JSON is encountered, the parser calls panic to unwind the stack to the top-level function call, which recovers from the panic and returns an appropriate error value (see the 'error' and 'unmarshal' methods of the decodeState type in decode.go).
The general consensus is to use a recover paradigm for the panics in the client package. And modify NewRuntime to return errors instead of panicking.
Generally I don't think it is good practice to panic in a library. Doing this assumes a number of things about the caller of the library:
I am not sure we should make these assumptions. In a situation where an error occurs I believe the lib should hand back control to the caller and allow it to decide what to do in that situation as the caller has the full context and domain knowledge.
The text was updated successfully, but these errors were encountered: