Skip to content

Commit 5d46b29

Browse files
committed
Update README.md
1 parent 32132ac commit 5d46b29

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

README.md

+35-28
Original file line numberDiff line numberDiff line change
@@ -2296,21 +2296,25 @@ Some of the common main thread exception are as follows:
22962296

22972297
**Throw** keyword is used in the method body to throw an exception, while **throws** is used in method signature to declare the exceptions that can occur in the statements present in the method.
22982298

2299-
**Throw Example:**
2299+
**Example:**
23002300

23012301
```java
2302-
public class ThrowExample {
2303-
void checkAge(int age) {
2304-
if(age < 18)
2305-
throw new ArithmeticException("Not Eligible for voting");
2306-
else
2307-
System.out.println("Eligible for voting");
2308-
}
2309-
public static void main(String args[]) {
2310-
ThrowExample obj = new ThrowExample();
2311-
obj.checkAge(13);
2312-
System.out.println("End Of Program");
2313-
}
2302+
/**
2303+
* Throw in Java
2304+
*/
2305+
public class ThrowExample {
2306+
void checkAge(int age) {
2307+
if (age < 18)
2308+
throw new ArithmeticException("Not Eligible for voting");
2309+
else
2310+
System.out.println("Eligible for voting");
2311+
}
2312+
2313+
public static void main(String args[]) {
2314+
ThrowExample obj = new ThrowExample();
2315+
obj.checkAge(13);
2316+
System.out.println("End Of Program");
2317+
}
23142318
}
23152319
```
23162320

@@ -2323,23 +2327,26 @@ at Example1.checkAge(Example1.java:4)
23232327
at Example1.main(Example1.java:10)
23242328
```
23252329

2326-
**Throws Example:**
2330+
**Example:**
23272331

23282332
```java
2329-
public class ThrowsExample {
2330-
int division(int a, int b) throws ArithmeticException {
2331-
int t = a/b;
2332-
return t;
2333-
}
2334-
public static void main(String args[]) {
2335-
ThrowsExample obj = new ThrowsExample();
2336-
try {
2337-
System.out.println(obj.division(15,0));
2338-
}
2339-
catch(ArithmeticException e) {
2340-
System.out.println("You shouldn't divide number by zero");
2341-
}
2342-
}
2333+
/**
2334+
* Throws in Java
2335+
*/
2336+
public class ThrowsExample {
2337+
int division(int a, int b) throws ArithmeticException {
2338+
int t = a / b;
2339+
return t;
2340+
}
2341+
2342+
public static void main(String args[]) {
2343+
ThrowsExample obj = new ThrowsExample();
2344+
try {
2345+
System.out.println(obj.division(15, 0));
2346+
} catch (ArithmeticException e) {
2347+
System.out.println("You shouldn't divide number by zero");
2348+
}
2349+
}
23432350
}
23442351
```
23452352

0 commit comments

Comments
 (0)