Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Teemu Auvinen
DTEK1066-ryhmis
Commits
73d72870
Commit
73d72870
authored
Dec 04, 2017
by
Matti Pulkkinen
Browse files
don't throw IOException out of main
parent
ab3349a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
DTEK1066-ryhmis/src/fi/utu/dtek1066/Main.java
View file @
73d72870
...
...
@@ -4,25 +4,39 @@ import java.io.IOException;
public
class
Main
{
// TODO don't throw IOException
public
static
void
main
(
String
[]
args
)
throws
IOException
{
SocketHandler
socketHandler
=
new
SocketHandler
();
StreamHandler
sh
=
socketHandler
.
openStreamHandler
();
public
static
void
main
(
String
[]
args
)
{
SocketHandler
socketHandler
=
null
;
StreamHandler
streamHandler
=
null
;
try
{
socketHandler
=
new
SocketHandler
();
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Failed to create SocketHandler object."
);
e
.
printStackTrace
();
System
.
exit
(
1
);
}
try
{
streamHandler
=
socketHandler
.
openStreamHandler
();
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Failed to open StreamHandler."
);
e
.
printStackTrace
();
System
.
exit
(
1
);
}
int
t
=
0
;
try
{
t
=
s
h
.
readInt
();
t
=
s
treamHandler
.
readInt
();
System
.
err
.
println
(
"Received t = "
+
t
);
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Failed
in
readin
g
t through ObjectInputStream."
);
System
.
err
.
println
(
"Failed
to
read
int through ObjectInputStream."
);
e
.
printStackTrace
();
}
if
(
t
<
2
||
t
>
10
)
{
System
.
err
.
println
(
"Illegal value t, sending response..."
);
try
{
s
h
.
writeInt
(-
1
);
s
treamHandler
.
writeInt
(-
1
);
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Failed
in
send
ing
response for illegal value."
);
System
.
out
.
println
(
"Failed
to
send response for illegal value."
);
e
.
printStackTrace
();
System
.
exit
(
2
);
}
...
...
@@ -30,10 +44,6 @@ public class Main {
System
.
exit
(
2
);
}
for
(
int
i
=
0
;
i
<
t
;
i
++)
{
int
r
=
(
int
)
(
Math
.
random
()
*
5000
+
1024
);
// TODO ensure no duplicates
sh
.
writeInt
(
r
);
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment