Home » Java programming language

Java Throwable fillInStackTrace() Method with Example

Throwable Class fillInStackTrace() method: Here, we are going to learn about the fillInStackTrace() method of Throwable Class with its syntax and example.
Submitted by Preeti Jain, on January 06, 2020

Throwable Class fillInStackTrace() method

  • fillInStackTrace() Method is available in java.lang package.
  • fillInStackTrace() Method is used to fills in the execution stack trace and this method records the current state of stack frames for this thread in this object.
  • fillInStackTrace() Method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • fillInStackTrace() Method does not throw an exception at the time of recording the current state of stack frames for this thread.

Syntax:

    public Throwable fillInStackTrace();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is Throwable, it returns reference to this Throwable object.

Example:

// Java program to demonstrate the example 
// of Throwable fillInStackTrace() method of Throwable 

public class FillInStackTrace {
    public static void main(String args[]) throws Throwable {
        // Creating an object of the class
        FillInStackTrace st_tr = new FillInStackTrace();

        try {
            // It will throw an exception while performing
            // divide operation
            st_tr.divM();
        } catch (Exception ex) {
            // By using fillInStackTrace() method is to
            // print exception information in detail
            ex.fillInStackTrace();
            ex.printStackTrace();
        }

    }
    //method calls
    public void divM() throws Throwable {
        div();
    }

    // This method will throw an exception
    //when number is divide by 0
    void div() {
        try {
            System.out.println(100 / 0);
        } catch (ArithmeticException ex) {
            throw ex;
        }
    }
}

Output

java.lang.ArithmeticException: / by zero
	at FillInStackTrace.main(FillInStackTrace.java:16)






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.






Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.