Skip to content

Instantly share code, notes, and snippets.

@wingyplus
Last active August 29, 2015 13:55
Show Gist options
  • Save wingyplus/8756590 to your computer and use it in GitHub Desktop.
Save wingyplus/8756590 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type MoneyNotEnoughError string
func (m MoneyNotEnoughError) Error() string {
return string(m)
}
type MoneyIsZeroError string
func (m MoneyIsZeroError) Error() string {
return string(m)
}
func checkMoney(n int) error {
if n == 0 {
return MoneyIsZeroError("money is zero error")
} else {
return MoneyNotEnoughError("money is not enough")
}
}
func main() {
err := checkMoney(0)
switch err.(type) {
case MoneyNotEnoughError:
fmt.Printf("money not enough")
case MoneyIsZeroError:
fmt.Printf("money zero")
}
}
class Money {
public void checkMoney(int n) throws MoneyNotEnoughError, MoneyIsZeroError {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment