-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathpyerrors.go
More file actions
34 lines (28 loc) · 803 Bytes
/
pyerrors.go
File metadata and controls
34 lines (28 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2017 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package pyerrors holds functions returning an error.
package pyerrors
import (
"errors"
"fmt"
)
// Div is a function for detecting errors.
func Div(i, j int) (int, error) {
if j == 0 {
return 0, errors.New("Divide by zero.")
}
return i / j, nil
}
type Stringer fmt.Stringer
type MyString string
func (t MyString) String() string { return string(t) }
// NewMyString converts a string to a custom MyString type.
// It is an error to pass an empty string value.
func NewMyString(val string) (stringer Stringer, err error) {
if val == "" {
err = errors.New("Empty string value.")
return
}
return MyString(val), nil
}