Safely divide 10 by 0 and print friendly message on error.
Ready — edit the code above and click Run.
using System;
class Program {
static void Main() {
int a = 10, b = 0;
try {
Console.WriteLine(a / b);
} catch (DivideByZeroException) {
Console.WriteLine("Cannot divide by zero");
}
}
}
Try solving on your own first, then reveal the official answer.
Catch specific exceptions first—interviewers want structured error handling, not empty catch.