import org.tkscommons.exception.TksException; public class ExceptionHandlingExample { public static void main(String[] args) { try { int result = divide(10, 0); System.out.println("Result: " + result); } catch (TksException ex) { System.out.println("An exception occurred: " + ex.getMessage()); ex.printStackTrace(); } } public static int divide(int num1, int num2) throws TksException { if (num2 == 0) { throw new TksException("Cannot divide by zero"); } return num1 / num2; } }


上一篇:
下一篇:
切换中文