Programmer's Wiki
Advertisement
16px-Pencil

Exceptions allow you to send a warning message to any programs that may be using your class. This allows the program to catch the Exception and deal with the problem.

Java[]

public void riskyTask() throws Exception{
	if(somethingBad == true) {
		Throw new Exception();
	}
}

the throws Exception warns anyone using this method to deal with the exception it might throw.

Advertisement