MCPcopy Index your code
hub / github.com/go-pg/pg / ExampleError

Function ExampleError

example_test.go:316–333  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

314}
315
316func ExampleError() {
317 video := &Video{
318 Id: 123,
319 }
320 _, err := pgdb.Model(video).Insert()
321 panicIf(err)
322
323 _, err = pgdb.Model(video).Insert()
324 if err != nil {
325 pgErr, ok := err.(pg.Error)
326 if ok && pgErr.IntegrityViolation() {
327 fmt.Println("video already exists:", err)
328 } else if pgErr.Field('S') == "PANIC" {
329 panic(err)
330 }
331 }
332 // Output: video already exists: ERROR #23505 duplicate key value violates unique constraint "videos_pkey"
333}

Callers

nothing calls this directly

Calls 5

InsertMethod · 0.80
panicIfFunction · 0.70
ModelMethod · 0.65
IntegrityViolationMethod · 0.65
FieldMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…