Junior — Middle
Kas saaksite selgitada, mis on kontrollitav erand programmeerimiskeeltes?
sobes.tech AI
Vastus AI-lt
Checked exception is a type of exception in Java that the compiler requires to be either handled (try-catch) or declared in the method signature using the throws keyword. They are intended for situations that may occur during execution but must be anticipated and handled by the programmer, such as input/output errors (IOException).
Example:
public void readFile(String path) throws IOException {
FileReader reader = new FileReader(path);
// ...
}
If a method calls another method that throws a checked exception, it must either handle the exception or declare it to be propagated. This helps make the code more reliable and clear regarding potential errors.