If you want to throw an exception in an apex class, following code will help ..

First you have to create your own Exception class like this:

public class applicationException extends Exception {}

Then you can throw an exception using following syntax

throw new applicationException(‘House Full’);

For e.g.,

public class MyException extends Exception {}
try {
Integer i;
// Your code here
if (i < 5) throw new MyException();
} catch (MyException e) {
// Your MyException handling code here
}