Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions 2.try-catch-finally/Doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Handling Exceptions
####● Two ways of handling exception
#####○ try-catch-finally
#####○ throws keyword
#####● Try-catch-finally handles exception where it occurs



#Try-Catch-Finally
####Consists of Three parts
######1.Try Block
######Risky codes goes here eg: System.out.println(5/0);
######2.Catch block
###### Handler code goes here eg: System.out.println(e.getMessage());
######3.Finally Block
######This will executed even though exception occurred or not Only JVM shutdown stop executing this part

#####● Try block can’t exist without catch block or finally block
#####● Catch or finally blocks cannot exist without try block
Comment on lines +1 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please elaborate more what is an exception and how it occurs.

17 changes: 17 additions & 0 deletions 2.try-catch-finally/Sample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Sample {
public static void main(String[] args){
try
{
System.out.println(5/0);

}
catch (Exception e){
System.out.println(e.getMessage());
}
finally {
System.out.println("Final code");
}
}

}

19 changes: 19 additions & 0 deletions try-catch-finally/Doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Handling Exceptions
####● Two ways of handling exception
#####○ try-catch-finally
#####○ throws keyword
#####● Try-catch-finally handles exception where it occurs



#Try-Catch-Finally
####Consists of Three parts
######1.Try Block
######Risky codes goes here eg: System.out.println(5/0);
######2.Catch block
###### Handler code goes here eg: System.out.println(e.getMessage());
######3.Finally Block
######This will executed even though exception occurred or not Only JVM shutdown stop executing this part

#####● Try block can’t exist without catch block or finally block
#####● Catch or finally blocks cannot exist without try block
17 changes: 17 additions & 0 deletions try-catch-finally/Sample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Sample {
public static void main(String[] args){
try
{
System.out.println(5/0);

}
catch (Exception e){
System.out.println(e.getMessage());
}
finally {
System.out.println("Final code");
}
}

}