0% found this document useful (0 votes)
5 views1 page

Java Lab-3

Exception handling in Java is a mechanism to detect, handle, and prevent program crashes caused by errors during execution. It involves using 'try' blocks to execute code that may cause an error and 'catch' blocks to handle those errors. An example demonstrates handling an ArithmeticException for division by zero.

Uploaded by

gadane720
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Java Lab-3

Exception handling in Java is a mechanism to detect, handle, and prevent program crashes caused by errors during execution. It involves using 'try' blocks to execute code that may cause an error and 'catch' blocks to handle those errors. An example demonstrates handling an ArithmeticException for division by zero.

Uploaded by

gadane720
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Exception Handling in Java

 Exception = an error that happens during program execution


 Exception Handling = a way to detect, handle, and prevent program crash
 try → code that may cause error
 catch → handles the error

try–catch Example

public class Example {


public static void main(String[] args) {
try {
int x = 10 / 0; // Error: division by zero
}
catch (ArithmeticException e) {
[Link]("Cannot divide by zero!");
}
}
}

You might also like