I have a class for an object, and if a user attempts to supply a negative number to it's constructor I want to output a warning telling them that they have provided an invalid number in the form of
System.out.println("ERROR ON LINE " + Thread.currentThread().getStackTrace()[2].getLineNumber() + ": You have provided an invalid number.\nSetting to default.");
EDIT: I set the values to a default values in the system, I don't want the program to terminate.
What I really want to know is how I do automagically find the [2].