0

I have a sample program as follows

public static void enterText(WebElement loc, String value) {
    try {
        loc.clear();
        System.out.println("Text cleared successfully");
    } catch (Exception e) {
        // exception handling
    }
}

On executing loc.clear(), a runtime exception occurs. Is there a way I can get the method name with parameters after exception happens. I need to get this enterText(WebElement loc, String value).

flaxel
  • 4,173
  • 4
  • 17
  • 30
chinnu Nish
  • 119
  • 1
  • 13
  • Does this answer your question? [Java exception handling](https://stackoverflow.com/questions/3625672/java-exception-handling) – flaxel Oct 04 '20 at 18:38

2 Answers2

0

You shall print the trace of the exception via this call: e.printStackTrace() inside catch block.

Mohammed Deifallah
  • 1,290
  • 1
  • 10
  • 25
0

You just need to add a "print" statement in the catch block.

public static void enterText(WebElement loc, String value) {
    try {
        loc.clear();
        System.out.println("Text cleared successfully");
    }
    catch (Exception e) {
        System.out.printf("ERROR: enterText( %s , %s )%n", loc, value);
        e.printStackTrace();
    }
}
Abra
  • 19,142
  • 7
  • 29
  • 41