Last active
August 29, 2015 13:55
-
-
Save wingyplus/8756590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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