SlideShare a Scribd company logo
INTRODUCTION TO EXCEPTION
HANDLING IN APEX
Presented By:
Omprakash Saini
An exception is a special condition that changes the
normal flow of program execution. That is, it's when
something bad happens that the program can't deal with
during execution. Exceptions are the language's way of
throwing up its hands and saying, "I can't deal with this,
you need to.“
WHAT IS A EXCEPTION:-
So what kinds of conditions can cause apex to raise, or throw, an
exception? Here are the most common examples:-
1. Your code expects a value from something that is currently null
2.An insert or update statement fails to pass a custom validation rule you
have set.
3.Assigning a query that returns no records or more than one record to a
singleton sobject variable.
4.Accessing a list index that is out of bounds.
CAUSES TO RAISE OR THROW AN EXCEPTION:-
1. When an exception occurs, and you haven't written any code to
deal with it, it's called 'unhandled.' First, an unhandled exception
brings processing to a halt. If the code that has processed so far
contained any database manipulation language (DML) statements,
those statements will be rolled back completely.
2.The system then notifies the running user of the problem. If you
you run into an exception in apex code while using the standard
user interface, a red text message will appear at the top of the
screen showing you the text of the unhandled exception.
WHAT HAPPENS WHEN AN EXCEPTION
OCCURS:-
The good news is that apex allows for you to handle your exceptions,
and write code to gracefully recover from an error. Apex uses the try,
catch, finally construct common to many other programming languages.
You "try" to run your code. If there is an exception, you "catch" it and can
run some code, then you can "finally" run some code whether you had
an exception or not.
You can have multiple catch blocks to catch any of the 20 different kinds
of exceptions. If you use a generic exception catcher, it must be the last
catch block.
HOW DO I CATCH EXCEPTION:-
HERE'S WHAT A TRY-CATCH-FINALLY BLOCK LOOKS
LIKE:-
try{
//your code here
}
catch(ListException e){
//optional catch of a specific exception type
//specific exception handling code here
}catch(Exception e){
//generic exception handling code here
}finally{
//optional finally block
//code whether there is an exception or not
}
HERE'S A TRY-CATCH EXAMPLE FOR AN APEX
CALLOUT:-
try{
HttpResponse res = http.send(req);
} catch(System.CalloutException e){
System.debug('ERROR:' + e);
}
HOW DO I HANDLE EXCEPTIONS THAT I'VE CAUGHT:-
1.DML:-
try{
update accounts;
} catch (dmlexception e){
for (account account : accounts) {
account.adderror('there was a problem updating the accounts');
}
} finally {
inprogress = false;
}
THANK YOU…

More Related Content

What's hot

Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
Forziatech
 
Html ppt
Html pptHtml ppt
Html ppt
jaswinder01
 
Web application development with laravel php framework version 4
Web application development with laravel php framework version 4Web application development with laravel php framework version 4
Web application development with laravel php framework version 4
Untung D Saptoto
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Pravin Pundge
 
Presentation swagger
Presentation swaggerPresentation swagger
Presentation swagger
François Robert
 
Bootstrap PPT by Mukesh
Bootstrap PPT by MukeshBootstrap PPT by Mukesh
Bootstrap PPT by Mukesh
Mukesh Kumar
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
amiable_indian
 
All of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperAll of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL Developer
Jeff Smith
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
Javascript
JavascriptJavascript
Javascript
guest03a6e6
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
 

What's hot (12)

Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
Html ppt
Html pptHtml ppt
Html ppt
 
Web application development with laravel php framework version 4
Web application development with laravel php framework version 4Web application development with laravel php framework version 4
Web application development with laravel php framework version 4
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Presentation swagger
Presentation swaggerPresentation swagger
Presentation swagger
 
Bootstrap PPT by Mukesh
Bootstrap PPT by MukeshBootstrap PPT by Mukesh
Bootstrap PPT by Mukesh
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
All of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperAll of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL Developer
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
Sql injection
Sql injectionSql injection
Sql injection
 

Viewers also liked

Cami Mansur
Cami MansurCami Mansur
Cami Mansur
Cami Mansur
 
Companies are Wasting Money on Content Marketing - and how to stop!
Companies are Wasting Money on Content Marketing - and how to stop!Companies are Wasting Money on Content Marketing - and how to stop!
Companies are Wasting Money on Content Marketing - and how to stop!
Scott Taylor
 
ГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушки
ГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушкиГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушки
ГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушки
Katerina Novoselova
 
Cartilla+impuesto+al+patrimonio+2011
Cartilla+impuesto+al+patrimonio+2011Cartilla+impuesto+al+patrimonio+2011
Cartilla+impuesto+al+patrimonio+2011
sandra miranda diaz
 
Imperialismo
ImperialismoImperialismo
Imperialismo
flkdncvjd
 
ГБОУ Школа№1238 7 группа Неделя здоровья
ГБОУ Школа№1238  7 группа Неделя здоровьяГБОУ Школа№1238  7 группа Неделя здоровья
ГБОУ Школа№1238 7 группа Неделя здоровья
Katerina Novoselova
 
ГБОУ Школа №1238 9 группа Неделя здоровья
ГБОУ Школа №1238  9 группа Неделя здоровьяГБОУ Школа №1238  9 группа Неделя здоровья
ГБОУ Школа №1238 9 группа Неделя здоровья
Katerina Novoselova
 
ГБОУ Школа №1238 Дошкольные группы: "Праздник осени" 10 группа
ГБОУ Школа №1238 Дошкольные группы: "Праздник осени"  10 группаГБОУ Школа №1238 Дошкольные группы: "Праздник осени"  10 группа
ГБОУ Школа №1238 Дошкольные группы: "Праздник осени" 10 группа
Katerina Novoselova
 
Náš pobyt v nórsku
Náš pobyt v nórskuNáš pobyt v nórsku
Náš pobyt v nórsku
Peter Karvai
 
Μαθητικό Συνέδριο Πληροφορικής
Μαθητικό Συνέδριο ΠληροφορικήςΜαθητικό Συνέδριο Πληροφορικής
Μαθητικό Συνέδριο ΠληροφορικήςDSChalkidona
 
Transtornos psicopatologicos
Transtornos psicopatologicosTranstornos psicopatologicos
Transtornos psicopatologicos
PSICOLOGIA Y EDUCACION INTEGRAL A.C.
 
CLAVES PARA LA CONSTRUCCIÓN DE CIUDADANÍA
CLAVES PARA LA CONSTRUCCIÓN DE CIUDADANÍACLAVES PARA LA CONSTRUCCIÓN DE CIUDADANÍA
CLAVES PARA LA CONSTRUCCIÓN DE CIUDADANÍA
PSICOLOGIA Y EDUCACION INTEGRAL A.C.
 
«BDD, Gherkin, Cucumber and why we need it for successful product development»
«BDD, Gherkin, Cucumber and why we need it for successful product development»«BDD, Gherkin, Cucumber and why we need it for successful product development»
«BDD, Gherkin, Cucumber and why we need it for successful product development»
Provectus
 
La Salud en la Venezuela Actual
La Salud en la Venezuela ActualLa Salud en la Venezuela Actual
La Salud en la Venezuela Actual
Carlos Macallums
 
Tratamiento digital de imagenes
Tratamiento digital de imagenesTratamiento digital de imagenes
Tratamiento digital de imagenesvfortea
 
3 t r
3 t r3 t r
3 t r
YchebnikRU
 

Viewers also liked (19)

Cami Mansur
Cami MansurCami Mansur
Cami Mansur
 
Companies are Wasting Money on Content Marketing - and how to stop!
Companies are Wasting Money on Content Marketing - and how to stop!Companies are Wasting Money on Content Marketing - and how to stop!
Companies are Wasting Money on Content Marketing - and how to stop!
 
ГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушки
ГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушкиГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушки
ГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушки
 
Desarrollo congnositivo 2da infancia
Desarrollo congnositivo 2da infanciaDesarrollo congnositivo 2da infancia
Desarrollo congnositivo 2da infancia
 
Cartilla+impuesto+al+patrimonio+2011
Cartilla+impuesto+al+patrimonio+2011Cartilla+impuesto+al+patrimonio+2011
Cartilla+impuesto+al+patrimonio+2011
 
Imperialismo
ImperialismoImperialismo
Imperialismo
 
ГБОУ Школа№1238 7 группа Неделя здоровья
ГБОУ Школа№1238  7 группа Неделя здоровьяГБОУ Школа№1238  7 группа Неделя здоровья
ГБОУ Школа№1238 7 группа Неделя здоровья
 
ГБОУ Школа №1238 9 группа Неделя здоровья
ГБОУ Школа №1238  9 группа Неделя здоровьяГБОУ Школа №1238  9 группа Неделя здоровья
ГБОУ Школа №1238 9 группа Неделя здоровья
 
ГБОУ Школа №1238 Дошкольные группы: "Праздник осени" 10 группа
ГБОУ Школа №1238 Дошкольные группы: "Праздник осени"  10 группаГБОУ Школа №1238 Дошкольные группы: "Праздник осени"  10 группа
ГБОУ Школа №1238 Дошкольные группы: "Праздник осени" 10 группа
 
Náš pobyt v nórsku
Náš pobyt v nórskuNáš pobyt v nórsku
Náš pobyt v nórsku
 
Μαθητικό Συνέδριο Πληροφορικής
Μαθητικό Συνέδριο ΠληροφορικήςΜαθητικό Συνέδριο Πληροφορικής
Μαθητικό Συνέδριο Πληροφορικής
 
Transtornos psicopatologicos
Transtornos psicopatologicosTranstornos psicopatologicos
Transtornos psicopatologicos
 
CLAVES PARA LA CONSTRUCCIÓN DE CIUDADANÍA
CLAVES PARA LA CONSTRUCCIÓN DE CIUDADANÍACLAVES PARA LA CONSTRUCCIÓN DE CIUDADANÍA
CLAVES PARA LA CONSTRUCCIÓN DE CIUDADANÍA
 
«BDD, Gherkin, Cucumber and why we need it for successful product development»
«BDD, Gherkin, Cucumber and why we need it for successful product development»«BDD, Gherkin, Cucumber and why we need it for successful product development»
«BDD, Gherkin, Cucumber and why we need it for successful product development»
 
Psicoanálisis
PsicoanálisisPsicoanálisis
Psicoanálisis
 
La Salud en la Venezuela Actual
La Salud en la Venezuela ActualLa Salud en la Venezuela Actual
La Salud en la Venezuela Actual
 
Tratamiento digital de imagenes
Tratamiento digital de imagenesTratamiento digital de imagenes
Tratamiento digital de imagenes
 
3 t r
3 t r3 t r
3 t r
 
Disease of Sorghum
Disease of SorghumDisease of Sorghum
Disease of Sorghum
 

Similar to Introduction to exception handling in apex

Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
Bharath K
 
6-Error Handling.pptx
6-Error Handling.pptx6-Error Handling.pptx
6-Error Handling.pptx
amiralicomsats3
 
Exception handling.pptx
Exception handling.pptxException handling.pptx
Exception handling.pptx
NISHASOMSCS113
 
Exception handling
Exception handlingException handling
Exception handling
Karthik Sekar
 
Introduction to Exception
Introduction to ExceptionIntroduction to Exception
Introduction to Exception
Swabhav Techlabs
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
siragezeynu
 
Java Exceptions Handling
Java Exceptions Handling Java Exceptions Handling
Java Exceptions Handling
DrRajeshreeKhande
 
Java Exceptions
Java ExceptionsJava Exceptions
Java Exceptions
jalinder123
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
Ashwin Shiv
 
JAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdfJAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdf
Prof. Dr. K. Adisesha
 
Py-Slides-9.ppt
Py-Slides-9.pptPy-Slides-9.ppt
Py-Slides-9.ppt
wulanpermatasari27
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
DrHemlathadhevi
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
AboMohammad10
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Ankit Rai
 
Chapter 13 exceptional handling
Chapter 13 exceptional handlingChapter 13 exceptional handling
Chapter 13 exceptional handling
Praveen M Jigajinni
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
Manav Prasad
 

Similar to Introduction to exception handling in apex (20)

Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
6-Error Handling.pptx
6-Error Handling.pptx6-Error Handling.pptx
6-Error Handling.pptx
 
Exception handling.pptx
Exception handling.pptxException handling.pptx
Exception handling.pptx
 
Exception handling
Exception handlingException handling
Exception handling
 
Introduction to Exception
Introduction to ExceptionIntroduction to Exception
Introduction to Exception
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Java Exceptions Handling
Java Exceptions Handling Java Exceptions Handling
Java Exceptions Handling
 
Java Exceptions
Java ExceptionsJava Exceptions
Java Exceptions
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
 
JAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdfJAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdf
 
Py-Slides-9.ppt
Py-Slides-9.pptPy-Slides-9.ppt
Py-Slides-9.ppt
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
$Cash
$Cash$Cash
$Cash
 
$Cash
$Cash$Cash
$Cash
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Chapter 13 exceptional handling
Chapter 13 exceptional handlingChapter 13 exceptional handling
Chapter 13 exceptional handling
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
 

Introduction to exception handling in apex

  • 1. INTRODUCTION TO EXCEPTION HANDLING IN APEX Presented By: Omprakash Saini
  • 2. An exception is a special condition that changes the normal flow of program execution. That is, it's when something bad happens that the program can't deal with during execution. Exceptions are the language's way of throwing up its hands and saying, "I can't deal with this, you need to.“ WHAT IS A EXCEPTION:-
  • 3. So what kinds of conditions can cause apex to raise, or throw, an exception? Here are the most common examples:- 1. Your code expects a value from something that is currently null 2.An insert or update statement fails to pass a custom validation rule you have set. 3.Assigning a query that returns no records or more than one record to a singleton sobject variable. 4.Accessing a list index that is out of bounds. CAUSES TO RAISE OR THROW AN EXCEPTION:-
  • 4. 1. When an exception occurs, and you haven't written any code to deal with it, it's called 'unhandled.' First, an unhandled exception brings processing to a halt. If the code that has processed so far contained any database manipulation language (DML) statements, those statements will be rolled back completely. 2.The system then notifies the running user of the problem. If you you run into an exception in apex code while using the standard user interface, a red text message will appear at the top of the screen showing you the text of the unhandled exception. WHAT HAPPENS WHEN AN EXCEPTION OCCURS:-
  • 5. The good news is that apex allows for you to handle your exceptions, and write code to gracefully recover from an error. Apex uses the try, catch, finally construct common to many other programming languages. You "try" to run your code. If there is an exception, you "catch" it and can run some code, then you can "finally" run some code whether you had an exception or not. You can have multiple catch blocks to catch any of the 20 different kinds of exceptions. If you use a generic exception catcher, it must be the last catch block. HOW DO I CATCH EXCEPTION:-
  • 6. HERE'S WHAT A TRY-CATCH-FINALLY BLOCK LOOKS LIKE:- try{ //your code here } catch(ListException e){ //optional catch of a specific exception type //specific exception handling code here }catch(Exception e){ //generic exception handling code here }finally{ //optional finally block //code whether there is an exception or not }
  • 7. HERE'S A TRY-CATCH EXAMPLE FOR AN APEX CALLOUT:- try{ HttpResponse res = http.send(req); } catch(System.CalloutException e){ System.debug('ERROR:' + e); }
  • 8. HOW DO I HANDLE EXCEPTIONS THAT I'VE CAUGHT:- 1.DML:- try{ update accounts; } catch (dmlexception e){ for (account account : accounts) { account.adderror('there was a problem updating the accounts'); } } finally { inprogress = false; }