+ Start a Discussion

Throwing Exceptions?

How do I throw one of the system defined exception types?

it says: throw <ExceptionObject>

I've tried:

throw new StringException();
throw new System.StringException();
throw StringException;

It returns the error message:

Exception type cannot be constructed

Ron HessRon Hess
i believe those are reserved for the system.

you should be able to create your own exception (possibaly extending a system exception) and then create and throw it.

let us know how this works, i've not tried it (yet)
So I added this class def. inside the class I was throwing the exception from:

public class NotificationRecordException extends Exception {}


public class NotificationRecord {
    public class NotificationRecordException extends Exception {}

    public static void testException() {
       throw new NotificationRecordException('There was an exception');

...... And then from another class's method:

try {
} catch ( NotificationRecord.NotificationRecordException e ) {