Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

in java how to throw exception from function

public void doChangePin(int oldPin, int pin) throws Exception {	//need to add throws followed by exception name
		if (oldPin == pinCode) {
			pinCode = pin;
		} else {
			throw new Exception("some message");	//throwing the exception by creating its new object
		}
	}
 
PREVIOUS NEXT
Tagged: #java #throw #exception #function
ADD COMMENT
Topic
Name
6+1 =