"Hi, Amigo!"

"Hi, Diego!"

"Here’s a small task about displaying the stack trace."

undefined
3
Task
Java Syntax, level 9, lesson 2
Locked
Returning a stack trace
The way a stack works is unfair and harsh. But sometimes it's so useful! Remember that the last function called is the first function to end. Let's practice and see what happens: we need to write five methods that call each other. Each method must return its stack trace.
undefined
6
Task
Java Syntax, level 9, lesson 2
Locked
Stack trace revisited
Let's get right down to business: write 5 methods that call each other. Each method should return the name of the method that called it. Use the stack trace to obtain this information. This name seems so beyond our reach. But we'll figure it out. These are just methods that sequentially call each other, nothing more.
undefined
3
Task
Java Syntax, level 9, lesson 2
Locked
Who called me?
The call stack may not be the most beautiful construct... But why not? It makes sense—you just need to get used to it. Let's get used to tasks! This time, you need to write five methods that call each other. Each method should return the line number of the code from which it was called. To do this, use the element.getLineNumber() method.
undefined
3
Task
Java Syntax, level 9, lesson 2
Locked
Stack trace with 10 calls
I got lucky: My favorite elementary school, Mrs. Turing, always wrote this phrase on the blackboard: "The last function called is the first function to end". She made us memorize it and swore that one day we would understand. Thank you, Mrs. Turing. It seems the promised day has come. I can even write code to get a stack trace that is 10 calls deep. Can you?
undefined
3
Task
Java Syntax, level 9, lesson 2
Locked
In the blue depths of the stack trace…
Remember the golden rule: function A calls function B, which calls function C. And to exit A, you must first exit B, and to do that you must exit C. Got it? Good. And now we'll write a method that returns the stack trace depth, i.e. the number of methods in the stack trace. And one more thing: display this number on the screen.
undefined
3
Task
Java Syntax, level 9, lesson 2
Locked
Logging stack traces
If you're approaching something more or less seriously, you will eventually come to some form of logging. Don't hesitate. Let's implement the log method. The log method should display the name of the class and method in which it is called, as well as the passed message. For clarity, use a colon and space to separate the class name, method name, and message.