- class SampleExe {
- void run() throws Exception {
- System.out.println("run before x");
- int x = 10 / 0;
- System.out.println("run after x");
- }
- }
- public class SmapleExe1 {
- public static void main(String[] args) {
- SampleExe exe = new SampleExe();
- exe.run();
- }
- }
Output: Unhandled type exception at compile time at line 12
--------------------------------------------------------------------
--------------------------------------------------------------------
- class SampleExe {
- void run() throws Exception {
- System.out.println("run before x");
- int x = 10 / 0;
- System.out.println("run after x");
- }
- }
- public class SmapleExe1 {
- public static void main(String[] args) throws Exception {
- SampleExe exe = new SampleExe();
- exe.run();
- }
- }
Output:
run before x
java.lang.ArithmeticException: / by zero at line 4
--------------------------------------------------------------------
- class SampleExe {
- void run() throws Exception {
- System.out.println("run before x");
- int x = 10 / 0;
- System.out.println("run after x");
- }
- }
- public class SmapleExe1 {
- public static void main(String[] args) {
- SampleExe exe = new SampleExe();
- try {
- exe.run();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Output:
run before x
java.lang.ArithmeticException: / by zero at line 4
No comments:
Post a Comment