Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Exception Handling using Java.#162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Sirajmolla merged 1 commit intocoder2hacker:mainfromPoulami-17:main
Oct 3, 2022
Merged
Changes fromall 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
39 changes: 39 additions & 0 deletionsException1.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
import java.util.*;
public class Exception1 {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a,b,result;
System.out.println("Enter the valyue of a and b: ");
a=sc.nextInt();
b=sc.nextInt();
try {
/*
This try{} block will hold those code ehich
may generate exxeption.
This try{} block will always be executed.
If any exception occurs, then only catch() {} block will be executed.
Otherwise catch() {} will not be executed.
*/
result=a/b;
System.out.println("the result is: "+result);
}
catch(Exception e){
/*
e is a reference to the instance of the Exception.

*/
System.out.println(e); //It will print the Exception.
System.out.println("b can't be 0.");
}

sc.close();
}

}

/*
If only the value od b = 0, then try block will generate
java.lang.ArithmeticException: / bu zero
then catch(){} block will be executed.
*/

[8]ページ先頭

©2009-2025 Movatter.jp