---
schema_version: "1"
id: 7206a58fe81f0d6cebfd864d6c96c49436f17e9f4a2abb1f007c06e07427f849
title: Exception Class and Built-In Exceptions
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_classes_exception_methods.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_exception_methods.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: fac3ba031f4cedee83cad71a891154d6238cdd78e493315736340079bd6f0cf0
description: An exception denotes an error that disrupts the normal flow of code execution. You can use Apex built-in exceptions or create custom exceptions. All exceptions have common methods.
---
# Exception Class and Built-In Exceptions

An exception denotes an error that disrupts the normal flow of code execution. You can use Apex built-in exceptions or create custom exceptions. All exceptions have common methods.

All exceptions support built-in methods for returning the error message and exception type. In addition to the standard exception class, there are several different types of exceptions:

The following are exceptions in the System namespace.

<table class="featureTable sort_table" summary="">


          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader vertical-align-top " id="d1621038e56">Exception</th>

              <th class="featureTableHeader vertical-align-top " id="d1621038e59">Description</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">AssertException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">A System.assert failure that halts code execution. Optionally
                contains the custom message specified in the last (<samp class="codeph apex_code">msg</samp>) argument to the <samp class="codeph apex_code">assert()</samp> method.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">AuraException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Legacy Aura-related exception. Use System.AuraHandledException
                instead.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">AuraHandledException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Returns a custom error message to a JavaScript controller. See <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.lightning.meta/lightning/controllers_server_apex_custom_errors.htm" target="_blank" title="HTML (New Window)">Returning
                  Errors from an Apex Server-Side Controller</a>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">AsyncException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with an asynchronous operation, such as failing to
                enqueue an asynchronous call. </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">BigObjectException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with big object records, such as connection timeouts
                during attempts to access or insert big object records.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">CalloutException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with a web service operation, such as failing to make a
                callout to an external system.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">DataWeaveScriptException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description"><span class="ph" id="DataWeaveExceptionDesc"><a name="DataWeaveExceptionDesc"><!-- --></a>Any run-time script errors that occur
                  within DataWeave in Apex.</span></td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">DmlException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description"><span class="ph" id="DMLExceptionDesc"><a name="DMLExceptionDesc"><!-- --></a>Any problem with a DML statement, such as
                  an <samp class="codeph apex_code"><span class="statement">insert</span></samp> statement missing
                  a required field on a record.</span></td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">DuplicateMessageException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description"><span class="ph" id="DuplicateMessageExceptionDesc"><a name="DuplicateMessageExceptionDesc"><!-- --></a>Attempt to enqueue job with
                  duplicate queueable signature</span></td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">EmailException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with email, such as failure to deliver. For more
                information, see <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_forcecom_email_outbound.htm" target="_blank">Outbound Email</a>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">ExternalObjectException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with external object records, such as connection timeouts
                during attempts to access the data that’s stored on external
                systems.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">FatalCursorException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with Apex cursors in a transaction.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">FinalException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any attempt to mutate a read-only collection or record such as an
                sObject in an after-update trigger, or a final variable. This exception
                causes execution to halt.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">FlowException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with starting flow interviews from Apex. For example, if
                an active version of the flow can’t be found or it can’t be started from
                Apex.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">HandledException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">A generic handled exception.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">IllegalArgumentException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">An illegal argument was provided to a method call. For example, a
                method that requires a non-null argument throws this exception if a null
                value is passed into the method.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph nolang">InvalidHeaderException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">An illegal header argument was provided to an Apex REST call. For
                example, a call to the <samp class="codeph ">RestResponse.addHeader(name, value)</samp> method throws this
                exception if the header name is <samp class="codeph ">cookie</samp>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">InvalidParameterValueException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">This exception is used with both Visualforce pages and Salesforce
                Functions. <ul class="ul bulletList">
                  <li class="li">
                    <strong class="ph b">Visualforce</strong>: The exception is thrown when an invalid parameter is
                    supplied for a method, or any problem is encountered with a
                    URL used with Visualforce pages. For more information on
                    Visualforce, see the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.pages.meta/pages/" target="_blank" title="Adobe Acrobat PDF (New Window)">Visualforce
                      Developer's Guide</a>.
                  </li>

                  <li class="li">
                    <strong class="ph b">Salesforce Functions</strong>: The exception is thrown when the <samp class="codeph ">functionName</samp>&nbsp;parameter to <samp class="codeph ">Function.get()</samp> doesn’t have
                    the correct&nbsp;<samp class="codeph ">project name.function
                      name</samp>&nbsp;format. For more information on Salesforce
                    functions, see <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_functions_Function.htm" target="_blank"><samp class="codeph ">Function.get()</samp></a>.
                  </li>

                </ul>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">LimitException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">A governor limit has been exceeded. This exception can’t be
                caught.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">JSONException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with JSON serialization and deserialization operations.
                For more information, see the methods of <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Json.htm#apex_class_System_Json" title="Contains methods for serializing Apex objects into JSON format and deserializing JSON content that was serialized using the serialize method in this class."><samp class="codeph apex_code">System.JSON</samp></a>, <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_JsonParser.htm#apex_class_System_JsonParser" title="Represents a parser for JSON-encoded content."><samp class="codeph apex_code">System.JSONParser</samp></a>, and
                <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_JsonGenerator.htm#apex_class_System_JsonGenerator" title="Contains methods used to serialize objects into JSON content using the standard JSON encoding."><samp class="codeph apex_code">System.JSONGenerator</samp></a>.
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">ListException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description"><span class="ph" id="ListExceptionDesc"><a name="ListExceptionDesc"><!-- --></a>Any problem with a list, such as
                  attempting to access an index that is out of bounds.</span></td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">MathException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with a mathematical operation, such as dividing by
                zero.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">NoAccessException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with unauthorized access, such as trying to access an
                sObject that the current user doesn’t have access to. This exception is
                used with Visualforce pages. For more information on Visualforce, see
                the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.pages.meta/pages/" target="_blank" title="Adobe Acrobat PDF (New Window)">Visualforce Developer
                  Guide</a>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">NoDataFoundException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">This exception is used with both Visualforce pages and Salesforce
                Functions. <ul class="ul bulletList">
                  <li class="li">
                    <strong class="ph b">Visualforce</strong>: The exception is thrown with data that doesn't exist, such
                    as trying to access an sObject that has been deleted. For
                    more information on Visualforce, see the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.pages.meta/pages/" target="_blank" title="Adobe Acrobat PDF (New Window)">Visualforce
                      Developer's Guide</a>.
                  </li>

                  <li class="li">
                    <strong class="ph b">Salesforce Functions</strong>: The exception is thrown when the project or function name
                    provided in the <samp class="codeph ">functionName</samp> parameter to the <samp class="codeph ">Function.get()</samp> method can't
                    be found. For more information on Salesforce functions, see
                    <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_functions_Function.htm" target="_blank"><samp class="codeph ">Function.get()</samp></a>.
                  </li>

                </ul>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">NoSuchElementException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">This exception is thrown if you try to access items that are outside
                the bounds of a list. This exception is used by the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_classes_iterable.htm" target="_blank">Iterator</a>
                <samp class="codeph apex_code">next</samp> method. For example, if
                <samp class="codeph apex_code">iterator.hasNext() == <span class="keyword">false</span></samp>
                and you call <samp class="codeph apex_code">iterator.next()</samp>,
                this exception is thrown. This exception is also used by the Apex Flex
                Queue methods and is thrown if you attempt to access a job at an invalid
                position in the flex queue.
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">NullPointerException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with dereferencing null. For an example, see <a class="xref" href="#ex_null_pointer">NullPointerException Example</a>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">QueryException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description"><span class="ph" id="QueryExceptionDesc"><a name="QueryExceptionDesc"><!-- --></a>Any problem with SOQL queries, such as
                  assigning a query that returns no records or more than one record to
                  a singleton sObject variable.</span></td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">RequiredFeatureMissing</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description"><span class="ph" id="chatter_missing"><a name="chatter_missing"><!-- --></a>A Chatter feature is required for code that
                  has been deployed to an organization that doesn’t have Chatter
                  enabled.</span></td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">SearchException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with SOSL queries executed with SOAP API <samp class="codeph apex_code">search()</samp> call, for example, when
                the <samp class="codeph apex_code">searchString</samp> parameter
                contains fewer than two characters. For more information, see the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.api.meta/api/" target="_blank" title="HTML (New Window)">SOAP API Developer
                  Guide</a>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">SecurityException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with static methods in the Crypto utility class. For more
                information, see <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_restful_crypto.htm#apex_classes_restful_crypto" title="Provides methods for creating digests, message authentication codes, and signatures, as well as encrypting and decrypting information.">Crypto Class</a>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">SerializationException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with the serialization of data. This exception is used
                with Visualforce pages. For more information on Visualforce, see the
                <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.pages.meta/pages/" target="_blank" title="Adobe Acrobat PDF (New Window)">Visualforce Developer
                  Guide</a>.
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">SObjectException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description"><span class="ph" id="SObjectExceptionDesc"><a name="SObjectExceptionDesc"><!-- --></a>Any problem with sObject records, such
                  as attempting to change a field in an <samp class="codeph apex_code"><span class="statement">update</span></samp> statement that can only
                  be changed during <samp class="codeph apex_code"><span class="statement">insert</span></samp>.</span></td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">StringException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with Strings, such as a String that is exceeding your
                heap size.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">TransientCursorException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">A transient problem with an Apex cursor transaction. The failed transaction can be retried.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">TypeException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with type conversions, such as attempting to convert the
                String 'a' to an Integer using the <samp class="codeph apex_code">valueOf</samp> method.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">UnexpectedException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">A non-recoverable internal error within Salesforce has occurred. This
                exception causes execution to halt. If necessary, contact Salesforce
                Customer Support for more information.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">VisualforceException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with a Visualforce page. For more information on
                Visualforce, see the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.pages.meta/pages/" target="_blank" title="Adobe Acrobat PDF (New Window)">Visualforce Developer
                  Guide</a>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e56" data-title="Exception"><samp class="codeph apex_code">XmlException</samp></td>

              <td class="entry" headers="d1621038e59" data-title="Description">Any problem with the XmlStream classes, such as failing to read or
                write XML.</td>

            </tr>

          </tbody>

        </table>

The following is an example using the DmlException exception:

Account\[\] accts = new Account\[\]{new Account(billingcity = 'San Jose')};
try {
    insert as user accts;
} catch (System.DmlException e) {
    for (Integer i = 0; i < e.getNumDml(); i++) {
        // Process exception here
        System.debug(e.getDmlMessage(i)); 
    }
}

For exceptions in other namespaces, see:

- [Cache Exceptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_cache_exceptions.htm "The Cache namespace contains exception classes.")
- [Canvas Exceptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_exceptions_canvas.htm "The Canvas namespace contains exception classes.")
- [Compression Exceptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_exceptions_compression.htm "The Compression namespace contains exception classes.")
- [ConnectApi Exceptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/connectAPI_exceptions.htm "The ConnectApi namespace contains exception classes.")
- [DataSource Exceptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_DataSource_exceptions.htm "The DataSource namespace contains exception classes.")
- [Reports Exceptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_Reports_exceptions.htm "The Reports namespace contains exception classes.")
- [Site Exceptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_Site_exceptions.htm "The Site namespace contains an exception class.")

## Common Exception Method

Exception methods are all called by and operate on an instance of an exception. This table describes all instance exception methods. All types of exceptions have these methods in common.

| Name | Arguments | Return Type | Description |
| --- | --- | --- | --- |
| getCause |  | Exception | Returns the cause of the exception as an exception object. |
| getLineNumber |  | Integer | Returns the line number from where the exception was thrown. |
| getMessage |  | String | Returns the error message that displays for the user. |
| getStackTraceString |  | String | Returns the stack trace of a thrown exception as a string. |
| getTypeName |  | String | Returns the type of exception, such as DmlException, ListException, MathException, and so on. |
| initCause | Exception cause | Void | Sets the cause for this exception, if one hasn’t already been set. |
| setMessage | String s | Void | Sets the error message that displays for the user. |

## DMLException and EmailException Methods

In addition to the common exception methods, DMLException and EmailException have these methods:

<table class="featureTable sort_table" summary="">




          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader vertical-align-top " id="d1621038e913">Name</th>

              <th class="featureTableHeader vertical-align-top " id="d1621038e916">Arguments</th>

              <th class="featureTableHeader vertical-align-top " id="d1621038e919">Return Type</th>

              <th class="featureTableHeader vertical-align-top " id="d1621038e922">Description</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d1621038e913" data-title="Name"><samp class="codeph apex_code">getDmlFieldNames</samp></td>

              <td class="entry" headers="d1621038e916" data-title="Arguments">Integer <var class="keyword varname">i</var>
              </td>

              <td class="entry" headers="d1621038e919" data-title="Return Type">String []</td>

              <td class="entry" headers="d1621038e922" data-title="Description">Returns the names of the field or fields that caused the error
                described by the <var class="keyword varname">i<sup class="ph sup">th</sup></var> failed row.
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e913" data-title="Name"><samp class="codeph apex_code">getDmlFields</samp></td>

              <td class="entry" headers="d1621038e916" data-title="Arguments">Integer <var class="keyword varname">i</var>
              </td>

              <td class="entry" headers="d1621038e919" data-title="Return Type">Schema.sObjectField []</td>

              <td class="entry" headers="d1621038e922" data-title="Description">Returns the field token or tokens for the field or fields that
                caused the error described by the <var class="keyword varname">i<sup class="ph sup">th</sup></var>
                failed row. For more information on field tokens, see <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_dynamic.htm" target="_blank">Dynamic Apex</a>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e913" data-title="Name"><samp class="codeph apex_code">getDmlId</samp></td>

              <td class="entry" headers="d1621038e916" data-title="Arguments">Integer <var class="keyword varname">i</var>
              </td>

              <td class="entry" headers="d1621038e919" data-title="Return Type">String</td>

              <td class="entry" headers="d1621038e922" data-title="Description">Returns the ID of the failed record that caused the error
                described by the <var class="keyword varname">i<sup class="ph sup">th</sup></var> failed
                row.</td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e913" data-title="Name"><samp class="codeph apex_code">getDmlIndex</samp></td>

              <td class="entry" headers="d1621038e916" data-title="Arguments">Integer <var class="keyword varname">i</var>
              </td>

              <td class="entry" headers="d1621038e919" data-title="Return Type">Integer</td>

              <td class="entry" headers="d1621038e922" data-title="Description">Returns the original row position of the
                <var class="keyword varname">i<sup class="ph sup">th</sup></var> failed row.
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e913" data-title="Name"><samp class="codeph apex_code">getDmlMessage</samp></td>

              <td class="entry" headers="d1621038e916" data-title="Arguments">Integer <var class="keyword varname">i</var>
              </td>

              <td class="entry" headers="d1621038e919" data-title="Return Type">String </td>

              <td class="entry" headers="d1621038e922" data-title="Description">Returns the user message for the
                <var class="keyword varname">i<sup class="ph sup">th</sup></var> failed row.
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e913" data-title="Name"><samp class="codeph apex_code">getDmlStatusCode</samp></td>

              <td class="entry" headers="d1621038e916" data-title="Arguments">Integer <var class="keyword varname">i</var>
              </td>

              <td class="entry" headers="d1621038e919" data-title="Return Type">String</td>

              <td class="entry" headers="d1621038e922" data-title="Description">Deprecated. Use getDmlType instead. Returns the Apex failure code
                for the <var class="keyword varname">i<sup class="ph sup">th</sup></var> failed row. </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e913" data-title="Name"><samp class="codeph apex_code">getDmlType</samp></td>

              <td class="entry" headers="d1621038e916" data-title="Arguments">Integer <var class="keyword varname">i</var>
              </td>

              <td class="entry" headers="d1621038e919" data-title="Return Type"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/langCon_apex_enums.htm" target="_blank">System.StatusCode</a></td>

              <td class="entry" headers="d1621038e922" data-title="Description">Returns the value of the System.StatusCode enum. For an example, see <a class="xref" href="#ex_dml_type">getDmlType Example</a>.<p class="p">For more information about System.StatusCode,
                  see <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/langCon_apex_enums.htm" target="_blank">Enums</a>.</p>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d1621038e913" data-title="Name"><samp class="codeph apex_code">getNumDml</samp></td>

              <td class="entry" headers="d1621038e916" data-title="Arguments"></td>

              <td class="entry" headers="d1621038e919" data-title="Return Type">Integer</td>

              <td class="entry" headers="d1621038e922" data-title="Description">Returns the number of failed rows for DML exceptions.</td>

            </tr>

          </tbody>

        </table>

## QueryException Method

In addition to the common exception methods, QueryException has this method.

<table class="featureTable sort_table" summary="">




          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader vertical-align-top " id="d1621038e1146">Name</th>

              <th class="featureTableHeader vertical-align-top " id="d1621038e1149">Arguments</th>

              <th class="featureTableHeader vertical-align-top " id="d1621038e1152">Return Type</th>

              <th class="featureTableHeader vertical-align-top " id="d1621038e1155">Description</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d1621038e1146" data-title="Name"><samp class="codeph ">getInaccessibleFields</samp></td>

              <td class="entry" headers="d1621038e1149" data-title="Arguments"></td>

              <td class="entry" headers="d1621038e1152" data-title="Return Type">
                <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_map.htm#apex_methods_system_map" title="Contains methods for the Map collection type.">Map</a>&lt;<a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string" title="Contains methods for the String primitive data type.">String</a>,<a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_set.htm#apex_methods_system_set" title="Represents a collection of unique elements with no duplicate values.">Set&lt;</a><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string" title="Contains methods for the String primitive data type.">String</a>&gt;&gt;
              </td>

              <td class="entry" headers="d1621038e1155" data-title="Description">Returns a map in which each key is an <samp class="codeph ">sObjectType</samp> and its corresponding value is the set of
                inaccessible field names in fully qualified format
                (Namespace__FieldName__c). <p class="p">Use this method to determine the cause
                  of the <samp class="codeph ">QueryException</samp>. The
                  returned map contains data only if the method that threw the
                  <samp class="codeph ">QueryException</samp> is running
                  in user mode.
                </p>
                <p class="p">For an example, see <a class="xref" href="#ex_inaccessible_fields">getInaccessibleFields Example</a>.</p>
              </td>

            </tr>

          </tbody>

        </table>

## NullPointerException Example

String s;
s.toLowerCase(); // Since s is null, this call causes
                 // a NullPointerException

## getDmlType Example

try {
  insert as user new Account();
}   catch (System.DmlException ex) {
      Assert.areEqual(
         StatusCode.REQUIRED\_FIELD\_MISSING,
         ex.getDmlType(0));
}

## getInaccessibleFields Example

In this code sample, it's assumed that the user doesn't have field level security access to the Contact.Email and Account.Website fields.

try {
    List<Account> accounts = \[SELECT Website, (SELECT Email FROM Contacts) FROM Account WITH USER\_MODE\];
} catch (QueryException qe) {
    // Handle inaccessible fields
    Map<String, Set<String\>> inaccessible = qe.getInaccessibleFields();
    Set<String\> accountFields = inaccessible.get('Account');
    Set<String\> contactFields = inaccessible.get('Contact');
}