To get the time when an exception occurred in Java, you can use the getTime()
method of the Throwable
class. This method returns the time when the exception was created, in milliseconds since the epoch (midnight, January 1, 1970 UTC).
Here's an example of how to use the getTime()
method to get the time when an exception occurred:
public class Main { public static void main(String[] args) { try { // some code that might throw an exception } catch (Exception e) { long exceptionTime = e.getTime(); System.out.println(exceptionTime); // prints the time when the exception occurred } } }Sourc.www:elautturi.com
In this example, an exception is caught in a catch
block. The getTime()
method of the Throwable
object is called to get the time when the exception occurred. The time is then printed to the console.
You can use the getTime()
method to log the time of the exception or to perform other operations on the time.