O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Create several classes and methods that will call each other, so you can perform stack trace processing.

  1. Create a Clazz01 class:
        public class Clazz01 {          public void method(){            new Clazz03().method("Do something");            new Clazz02().method();          }        }
  1. Create a Clazz02 class:
        public class Clazz02 {          public void method(){            new Clazz03().method(null);          }        }
  1. Create a Clazz03 class:
        public class Clazz03 {          public void method(String action){            if(action != null){              System.out.println(action);              return;            }            System.out.println("Throw the exception:");            action.toString();          }        }
  1. Write a demo4_StackWalk() method:
        private static void demo4_StackWalk(){          new Clazz01().method();        }

Call this method from the main method of the Chapter12Memory class:

 public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required