The generic name used for unexpected errors that occur during the execution of a program is

infractions
exceptions
deviations
anomalies

The correct answer is: B. exceptions

An exception is an unexpected event that occurs during the execution of a program. It can be caused by a variety of factors, such as a division by zero, an attempt to access a non-existent memory location, or a user input that is not valid. When an exception occurs, the program is typically terminated. However, it is possible to handle exceptions in a way that allows the program to continue running.

There are two types of exceptions: checked exceptions and unchecked exceptions. Checked exceptions are those that are declared in the method signature. Unchecked exceptions are those that are not declared in the method signature.

Checked exceptions must be handled by the method that throws them. If a checked exception is not handled, the compiler will generate an error. Unchecked exceptions do not need to be handled by the method that throws them. However, if an unchecked exception is not handled, the program will be terminated.

To handle an exception, you can use the try-catch statement. The try block contains the code that is potentially dangerous. The catch block contains the code that is executed if an exception occurs.

For example, the following code shows how to handle a division by zero exception:

int x = 10;
int y = 0;
try {
int z = x / y;
} catch (ArithmeticException e) {
System.out.println("Division by zero");
}

In this example, the try block contains the code that is potentially dangerous. The catch block contains the code that is executed if an exception occurs. In this case, the catch block prints a message to the console.

Exceptions are an important part of programming. They allow you to handle unexpected events in a way that is safe and reliable.

The other options are incorrect because they do not accurately describe unexpected errors that occur during the execution of a program.

  • Infractions are violations of rules or regulations.
  • Deviations are departures from what is expected or usual.
  • Anomalies are things that are unusual or abnormal.
Exit mobile version