Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 526 Bytes

type-assert.md

File metadata and controls

30 lines (22 loc) · 526 Bytes

Handle Type Assertion Failures

The single return value form of a type assertion will panic on an incorrect type. Therefore, always use the "comma ok" idiom.

BadGood
t := i.(string)
t, ok := i.(string)
if !ok {
  // handle the error gracefully
}