Use printStackTrace() method to generate stack

Stack trace is a kind of call stack, which maintains the call sequence of methods at any given point in time. Throwable class in Java provides a method called “printStackTrace()” which can be used to print out the entire stack trace. You can use this method during debugging complex bug as it prints out the entire stack trace to the standard error stream.

There are a couple of ways of using this method:

a)You can call this method from the catch() block. This is the most common usage of this method.

 catch (Throwable t){    t.printStackTrace();}


(b) You can put following statement anywhere in your code to print the stack trace to standard error stream.

 new Throwable().printStackTrace();

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a