Exceptions in Apex-Apex uses exceptions to note errors and other events that disrupt the normal flow of code execution. throw statements can be used to generate exceptions, while try, catch, and finally can be used to gracefully recover from an exception.
Exceptions that Can’t be Caught- Some special types of built-in exceptions can’t be caught. Those exceptions are associated with critical situations in the Lightning Platform
example limitexception
Built-In Exceptions and Common Methods-
DmlException,
ListException,
NullPointerException,
QueryException,
SObjectException
getCause: Returns the cause of the exception as an exception object.
getLineNumber: Returns the line number from where the exception was thrown.
getMessage: Returns the error message that displays for the user.
getStackTraceString: Returns the stack trace of a thrown exception as a string.
getTypeName: Returns the type of exception, such as DmlException, ListException, MathException, and so on.
Alternatively, you can have several catch blocks—a catch block for each exception type, and a final catch block that catches the generic Exception type

0 Comments