Exception handling in Object Pascal - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: Object Pascal Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=50) +--- Thread: Exception handling in Object Pascal (/showthread.php?tid=5049) |
Exception handling in Object Pascal - Qomplainerz - 07-25-2023 program ExceptionHandlingExample; var num1, num2, result: Integer; begin try Write('Enter the first number: '); ReadLn(num1); Write('Enter the second number: '); ReadLn(num2); if num2 = 0 then raise Exception.Create('Division by zero is not allowed.'); result := num1 div num2; WriteLn('Result: ', result); except on E: Exception do WriteLn('Exception caught: ', E.Message); end; end. |