Contents[Hide]

Throwing own errors

To define my own error I decided to group them in separate class for easy maintaining.

public class my_Exceptions {

    /* License Generator Exceptions */
    public virtual class mainException extends Exception {}
        // Sub exceptions
        public class morePrecisedException extends licGenException {}
       
}

Class "mainException" must have a virtual modifier to be extendable. See Defining Apex Classes documentation.

Now use it in apex class:

throw new my_Exceptions.morePrecisedException();

Cach this exception:

 

or any of precised exception by the class from which they inherit.

 

More knowledge:

Using Exception Methods
An Introduction to Exception Handling
Defining Apex Classes

a

 

   
© Paweł Woźniak