Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Random Class With Exceptions #16

Open
volodya-lombrozo opened this issue Nov 29, 2023 · 0 comments
Open

Generate Random Class With Exceptions #16

volodya-lombrozo opened this issue Nov 29, 2023 · 0 comments
Labels
enhancement New feature or request not-urgent This is not an urgent task

Comments

@volodya-lombrozo
Copy link
Owner

As a developer I would like to test compilation of java classes with exceptions and different forms of try-catch clause:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ExceptionExample {
    public static void main(String[] args) {
        // Example of try-catch block
        try {
            int result = divide(10, 0);
            System.out.println("Result: " + result);
        } catch (ArithmeticException e) {
            System.err.println("Error: " + e.getMessage());
        }

        // Example of try-catch with resources
        try (BufferedReader reader = new BufferedReader(new FileReader("nonexistent-file.txt"))) {
            String line = reader.readLine();
            System.out.println("First line of file: " + line);
        } catch (IOException e) {
            System.err.println("Error reading file: " + e.getMessage());
        }
    }

    // Method that may throw an exception
    private static int divide(int numerator, int denominator) {
        return numerator / denominator;
    }
}
@volodya-lombrozo volodya-lombrozo added enhancement New feature or request not-urgent This is not an urgent task labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request not-urgent This is not an urgent task
Projects
None yet
Development

No branches or pull requests

1 participant