Is there any way in Java to find out "who"/"what" threw the excpetion?
consider the following code which validates a couple of Textfields (which have certain constraint on what input is valid or not). I want to mark the corresponding textfield red.
public void validateInput() {
try {
textfieldName.validate();
textfieldAge.validate();
} catch (InvalidInputExcpetion e) {
// Pseudocode
// e.getThrower() would get me the reference to the Object which threw the exception
(TextField e.getThrower()).markRed();
}
}
The only solution I found is to extend my custom excpetion to hold a reference to the throwing textfield, isn't there an easier way?