From a594dda52961ee6f8cac2621ba8d70ba6e9a5d48 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sun, 31 Dec 2017 16:59:48 +0000 Subject: [PATCH] changed exception handling in Socket>>fromString: --- moo/kernel/Socket.moo | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index bcc30be..fb9c446 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -25,7 +25,7 @@ class(#byte) IP4Address(IPAddress) ^self new fromString: str. } - method fromString: str + method __fromString: str { | dots digits pos size c acc | @@ -40,10 +40,7 @@ class(#byte) IP4Address(IPAddress) { if (pos >= size) { - if (dots < 3 or: [digits == 0]) - { - Exception signal: ('invalid IPv4 address A ' & str). - }. + if (dots < 3 or: [digits == 0]) { ^Error.Code.EINVAL }. self basicAt: dots put: acc. break. }. @@ -59,7 +56,7 @@ class(#byte) IP4Address(IPAddress) } elsif (c = $.) { - if (dots >= 3 or: [digits == 0]) { Exception signal: ('invalid IPv4 address C ' & str). }. + if (dots >= 3 or: [digits == 0]) { ^Error.Code.EINVAL }. self basicAt: dots put: acc. dots := dots + 1. acc := 0. @@ -67,12 +64,25 @@ class(#byte) IP4Address(IPAddress) } else { - Exception signal: ('invalid IPv4 address ' & str). + ^Error.Code.EINVAL + ### goto @label@. }. - - } while (true). + + ^self. +(* + (@label@) + Exception signal: ('invalid IPv4 address ' & str). +*) + } + + method fromString: str + { + if ((self __fromString: str) isError) + { + Exception signal: ('invalid IPv4 address ' & str). + } } }