SlideShare uma empresa Scribd logo
1 de 9
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…

Mais conteúdo relacionado

Mais procurados

実録!Railsのはまりポイント10選
実録!Railsのはまりポイント10選実録!Railsのはまりポイント10選
実録!Railsのはまりポイント10選
Drecom Co., Ltd.
 

Mais procurados (20)

Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
事例から探る、Redmineの機能とよりよい運用
事例から探る、Redmineの機能とよりよい運用事例から探る、Redmineの機能とよりよい運用
事例から探る、Redmineの機能とよりよい運用
 
ReactでuseEffect()を減らしたい話
ReactでuseEffect()を減らしたい話ReactでuseEffect()を減らしたい話
ReactでuseEffect()を減らしたい話
 
ビュー索引のキホン(後編)
ビュー索引のキホン(後編)ビュー索引のキホン(後編)
ビュー索引のキホン(後編)
 
20160906 pplss ishizaki public
20160906 pplss ishizaki public20160906 pplss ishizaki public
20160906 pplss ishizaki public
 
Jbatch実践入門 #jdt2015
Jbatch実践入門 #jdt2015Jbatch実践入門 #jdt2015
Jbatch実践入門 #jdt2015
 
EventListener使いこなし術 - Symfony勉強会#10
EventListener使いこなし術 - Symfony勉強会#10EventListener使いこなし術 - Symfony勉強会#10
EventListener使いこなし術 - Symfony勉強会#10
 
20120711 WUM Redmineの使い道_公開版
20120711 WUM Redmineの使い道_公開版20120711 WUM Redmineの使い道_公開版
20120711 WUM Redmineの使い道_公開版
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
Solid principles
Solid principlesSolid principles
Solid principles
 
実録!Railsのはまりポイント10選
実録!Railsのはまりポイント10選実録!Railsのはまりポイント10選
実録!Railsのはまりポイント10選
 
"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy
 
Solid Principle
Solid PrincipleSolid Principle
Solid Principle
 
サーバ構築を自動化する 〜Ansible〜
サーバ構築を自動化する 〜Ansible〜サーバ構築を自動化する 〜Ansible〜
サーバ構築を自動化する 〜Ansible〜
 
Ruby での外部コマンドの実行について
Ruby での外部コマンドの実行についてRuby での外部コマンドの実行について
Ruby での外部コマンドの実行について
 
ふつうのRailsアプリケーション開発
ふつうのRailsアプリケーション開発ふつうのRailsアプリケーション開発
ふつうのRailsアプリケーション開発
 
Redmineをちょっと便利に! プログラミング無しで使ってみるREST API
Redmineをちょっと便利に! プログラミング無しで使ってみるREST APIRedmineをちょっと便利に! プログラミング無しで使ってみるREST API
Redmineをちょっと便利に! プログラミング無しで使ってみるREST API
 
202206_採用ピッチ資料_株式会社アスペア.pdf
202206_採用ピッチ資料_株式会社アスペア.pdf202206_採用ピッチ資料_株式会社アスペア.pdf
202206_採用ピッチ資料_株式会社アスペア.pdf
 
よくある質問と対策 2015
よくある質問と対策 2015よくある質問と対策 2015
よくある質問と対策 2015
 
プログラミング言語Clojureのニャンパスでの活用事例
プログラミング言語Clojureのニャンパスでの活用事例プログラミング言語Clojureのニャンパスでの活用事例
プログラミング言語Clojureのニャンパスでの活用事例
 

Destaque

ГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушки
ГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушкиГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушки
ГБОУ Школа №1238 Дошкольные группы: 7 группа неделя игрушки
Katerina Novoselova
 
ГБОУ Школа№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
 
Μαθητικό Συνέδριο Πληροφορικής
Μαθητικό Συνέδριο ΠληροφορικήςΜαθητικό Συνέδριο Πληροφορικής
Μαθητικό Συνέδριο Πληροφορικής
DSChalkidona
 
Tratamiento digital de imagenes
Tratamiento digital de imagenesTratamiento digital de imagenes
Tratamiento digital de imagenes
vfortea
 

Destaque (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
 

Semelhante a Introduction to exception handling in apex

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
 

Semelhante a 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
Java ExceptionsJava Exceptions
Java Exceptions
 
Java Exceptions Handling
Java Exceptions Handling Java Exceptions Handling
Java Exceptions Handling
 
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; }