-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.tex
More file actions
35 lines (33 loc) · 842 Bytes
/
exception.tex
File metadata and controls
35 lines (33 loc) · 842 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
35
\pagebreak{}
\section{Exception Handling}
\begin{verbatim}
public class Error {
public static void main(String[] args) {
int invalid = 0;
int num, count = 0;
for (int i = 0; i < args.length; i++)
{
try {
num=Integer.parseInt(args[i]);
}
catch (NumberFormatException e) {
invalid=invalid+1;
System.out.println("invalid op:"+args[i]);
continue;
}
count = count+1;
}
System.out.println("valid no:"+count);
System.out.println("invalid no:"+invalid);
}
}
\end{verbatim}
\section*{Output}
\begin{verbatim}
>: java Error 9 asd a 2 45 d
invalid op:asd
invalid op:a
invalid op:d
valid no:3
invalid no:3
\end{verbatim}