Friday, February 22, 2019

How to show custom exception message in apex

This post explains how to show the custom exception in the apex
If you want to show any custom exceptions in the apex, create custom exception class and extends the standard Exception Class.
Apex Class
public class CustomExceptionController {
    public static void throwCustomException() {
        try {
            throw new customDemoException('This is Custom Exception Message');
        catch(Exception ex) {
            System.debug('Custom Exception Message ===> '+ex.getMessage());
// custom exception class
public class customDemoException extends Exception {}
Run below code from the anonymous window.


No comments:

Post a Comment