কম্পিউটার টিউটোরিয়াল

জাভাতে fillInStackTrace() মেথড কখন ব্যবহার করব

fillInStackTrace() হলো জাভার Throwable ক্লাসের একটি গুরুত্বপূর্ণ মেথড। স্ট্যাক ট্রেস থেকে এক্সসেপশন কোথায় থ্রো হয়েছে তা নির্ধারণ করা যায়। কিছু পরিস্থিতিতে এক্সসেপশন রি-থ্রো করতে হয় এবং সেটি কোথায় রি-থ্রো হয়েছে তা জানতে হলে fillInStackTrace() মেথড ব্যবহার করা যায়।

সিনট্যাক্স

public Throwable fillInStackTrace()

উদাহরণ

public class FillInStackTraceTest { 
    public static void method1() throws Exception { 
        throw new Exception("This is thrown from method1()"); 
    } 
    public static void method2() throws Throwable { 
        try { 
            method1(); 
        } catch(Exception e) { 
            System.err.println("Inside method2():"); 
            e.printStackTrace(); 
            throw e.fillInStackTrace(); // fillInStackTrace() মেথড কল 
        } 
    } 
    public static void main(String[] args) throws Throwable { 
        try { 
            method2(); 
        } catch (Exception e) { 
            System.err.println("Caught Inside Main method()"); 
            e.printStackTrace(); 
        } 
    } 
}

আউটপুট

Inside method2(): java.lang.Exception: This is thrown from method1() 
     at FillInStackTraceTest.method1(FillInStackTraceTest.java:3) 
     at FillInStackTraceTest.method2(FillInStackTraceTest.java:7) 
     at FillInStackTraceTest.main(FillInStackTraceTest.java:18) 
Caught Inside Main method() java.lang.Exception: This is thrown from method1() 
     at FillInStackTraceTest.method2(FillInStackTraceTest.java:12) 
     at FillInStackTraceTest.main(FillInStackTraceTest.java:18)
  1. জাভাতে pack() মেথড কখন ব্যবহার করবেন

  2. জাভাতে setBounds() মেথডের ব্যবহার কী?

  3. জাভাতে String ক্লাসের intern() মেথড কখন ব্যবহার করবেন?

  4. জাভাতে কখন অ্যাবস্ট্রাক্ট ক্লাস এবং কখন ইন্টারফেস ব্যবহার করবেন?