SlideShare a Scribd company logo
1 of 17
Hi friends
C# Tutorial
Part 41:
ERROR
www.siri-kt.blogspot.com
• Errors refer to the mistake or faults which occur
during program development or execution. If you
don't find them and correct them, they cause a
program to produce wrong results.
• Types of Errors
• In programming language errors can be divided into
three categories as given below-
• Syntax Errors:
• Syntax errors occur during development, when you make
type mistake in code. For example, instead of writing
while, you write WHILE then it will be a syntax error
since C# is a case sensitive language.
• bool flag=true;
• WHILE (flag) //syntax error, since c# is case sensitive
• {
• //TO DO:
• }
• Runtime Errors (Exceptions):
• Runtime errors occur during execution of the
program. These are also called exceptions. This can
be caused due to improper user inputs, improper
design logic or system errors.
– int a = 5, b = 0;
– int result = a / b; // DivideByZeroException
• Exceptions can be handled by using try-catch
blocks.
• Logical Errors
• Logic errors occur when the program is written fine
but it does not produce desired result. Logic errors
are difficult to find because you need to know for
sure that the result is wrong
• int a = 5, b = 6;
• double avg = a + b / 2.0; // logical error, it should
be (a + b) / 2.0
• Exception Handling
• Exception handling is a mechanism to detect and handle
run time errors. It is achieved by using Try-Catch-
Finally blocks and throw keyword.
• Try block
• The try block encloses the statements that might throw
an exception.
– try
– {
– // Statements that can cause exception.
– }
• the microsoft given 4 keywords for handling Runtime errors
• 1.try
• 2.catch
• 3.finally
• 4.Throw
• if we are not expect any errors in an application then we can't work with exception
handling.
• syntax:
• try
• { expected error information }
• catch
• { exception information }
• finally
• { Result(o/p) }
• throw
• { user defined exception }
• 1.try:
• in the try block we have to include all expected
exceptions statements. try block followed with cacth
&finally,catch (or)finally one try block may having
multiple catch blocks but having only one finally block.
one try block raising only one exception at a time.one try
block can executes one catch block at time
• 2.catch:
• using catch block we can provide exception
information.one catch block can handles only one
exception
• 3.finally block:
• the finally block executes which statements doesn't
• 4.throw:
• throw bloack can handle only one userdefined exception at a time. this block can handle
multiple userdefined exceptions at a time.
• example exception Handling:
• static void Main(string[] args)
• { try
• { int a, b, c;
• Console.WriteLine("enter a value");
• a=int.Parse(Console.ReadLine());
• Console.WriteLine("enter b value");
• b=int.Parse(Console.ReadLine());
• c = a / b;
• Console.WriteLine(c.ToString());
• Console.ReadLine(); }
• catch (Exception ex)
• { Console.WriteLine(ex.ToString());
• Console.ReadLine(); }
• ex2:
• 1.take a form
• 2.add 3 label,3 textboxes&one button
• source code:
• private void button1_Click(object sender, EventArgs e)
• { int a, b, res = 0;
• try
• { a = Convert.ToInt16(textBox1.Text);
• b = Convert.ToInt16(textBox2.Text);
• res = a / b; }
• catch (Exception ex)
• { MessageBox.Show(ex.Message); }
• finally
• { textBox3.Text = res.ToString(); } }
• Catch block
• Catch block handles any exception if one exists.
– catch(ExceptionType e)
– {
– // Statements to handle exception.
– }
• Finally block
• The finally block can be used for doing any clean-up process like releasing
unused resources even if an exception is thrown. For example, disposing
database connection.
– finally
– {
– // Statement to clean up.
– }
– Throw keyword
– This keyword is used to throw an exception explicitly.
– catch (Exception e)
– {
– throw (e);
– }
• Key points about exceptions handling
• Exceptions are types that all directly or indirectly
derive from System.Exception class.
• Exception objects contain detailed information about
the error, such as the state of the call stack and a text
description of the error.
• A try block is used to throw multiple exceptions that can
handle by using multiple catch blocks.
• More specialized catch block should come before a
generalized one. Otherwise specialized catch block will
never be executed.
• Exceptions can be explicitly generated by a program by
using the throw keyword.
• If no exception handling mechanism is used, the program
stops executing with an error message.
• By providing a catch block without a brackets or arguments,
we can catch all exceptions occurred inside a try block.
– Catch
– { Console.WriteLine("oException" ); }
• By providing a catch block with an exception object, you can
obtain more information about the type of exception that
occurred.
– catch(Exception e)
– { Console.WriteLine(e.Message); }
• The statements inside the finally block are always executed
whether exception occurs or not in the program.
• Also, before the termination of the program finally block is
always executed.
Order of Try-Catch-Finally blocks
• In the order of exceptions handling blocks try block comes first, after
that catch block(s) come and in the last finally block come.
• try
• { // statements that can cause exception. }
• catch (MoreSpecificExceptionType e1)
• { // error handling code }
• catch (SpecificExceptionType e2)
• { // error handling code }
• catch (GeneralExceptionType eN)
• { // error handling code }
• finally
• { // statement to clean up. }
You can also skip finally block if
required.
• try
• { // statements that can cause exception. }
• catch (MoreSpecificExceptionType e1)
• { // error handling code }
• catch (SpecificExceptionType e2)
• { // error handling code }
• catch (GeneralExceptionType eN)
• { // error handling code }
• You can also skip catch block(s) if required.
• try
• { // statements that can cause exception. }
• finally
• { // statement to clean up. }
• Hence a combination of try-catch-finally or try-catch or try-finally blocks is valid.
For more visit our website www.siri-kt.blogspot.com
Thanks for
Watching
More Angular JS TutorialsMore C sharp (c#) tutorials

More Related Content

What's hot

Exception handling in c
Exception handling in cException handling in c
Exception handling in cMemo Yekem
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Edureka!
 
Exception Handling
Exception HandlingException Handling
Exception Handlingbackdoor
 
Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in javajunnubabu
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handlingMohammed Sikander
 
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsRanel Padon
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in pythonjunnubabu
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Janki Shah
 
What is Exception Handling?
What is Exception Handling?What is Exception Handling?
What is Exception Handling?Syed Bahadur Shah
 
Exception Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim MullerException Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim MullerByte
 
Understanding Exception Handling in .Net
Understanding Exception Handling in .NetUnderstanding Exception Handling in .Net
Understanding Exception Handling in .NetMindfire Solutions
 
Types of exceptions
Types of exceptionsTypes of exceptions
Types of exceptionsmyrajendra
 
Chapter v(error)
Chapter v(error)Chapter v(error)
Chapter v(error)Chhom Karath
 

What's hot (20)

Exception handling in c
Exception handling in cException handling in c
Exception handling in c
 
Exceptions in python
Exceptions in pythonExceptions in python
Exceptions in python
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Exception handling in python
Exception handling in pythonException handling in python
Exception handling in python
 
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in java
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Presentation1
Presentation1Presentation1
Presentation1
 
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in python
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
What is Exception Handling?
What is Exception Handling?What is Exception Handling?
What is Exception Handling?
 
Exception Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim MullerException Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim Muller
 
Understanding Exception Handling in .Net
Understanding Exception Handling in .NetUnderstanding Exception Handling in .Net
Understanding Exception Handling in .Net
 
Types of exceptions
Types of exceptionsTypes of exceptions
Types of exceptions
 
C++ ala
C++ alaC++ ala
C++ ala
 
Chapter v(error)
Chapter v(error)Chapter v(error)
Chapter v(error)
 

Similar to 41c

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 allHayomeTakele
 
Multi catch statement
Multi catch statementMulti catch statement
Multi catch statementmyrajendra
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
Java class 7
Java class 7Java class 7
Java class 7Edureka!
 
Exception handling in java-PPT.pptx
Exception handling in java-PPT.pptxException handling in java-PPT.pptx
Exception handling in java-PPT.pptxsonalipatil225940
 
Exception Handling on 22nd March 2022.ppt
Exception Handling on 22nd March 2022.pptException Handling on 22nd March 2022.ppt
Exception Handling on 22nd March 2022.pptRaja Ram Dutta
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javapriyankazope
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handlingraksharao
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingraksharao
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15Kumar
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)SURBHI SAROHA
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception HandlingMaqdamYasir
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java yugandhar vadlamudi
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overviewBharath K
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaKavitha713564
 
PROGRAMMING IN JAVA
PROGRAMMING IN JAVAPROGRAMMING IN JAVA
PROGRAMMING IN JAVASivaSankari36
 

Similar to 41c (20)

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
 
Multi catch statement
Multi catch statementMulti catch statement
Multi catch statement
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
Java class 7
Java class 7Java class 7
Java class 7
 
ACP - Week - 9.pptx
ACP - Week - 9.pptxACP - Week - 9.pptx
ACP - Week - 9.pptx
 
Exception handling in java-PPT.pptx
Exception handling in java-PPT.pptxException handling in java-PPT.pptx
Exception handling in java-PPT.pptx
 
Exception Handling on 22nd March 2022.ppt
Exception Handling on 22nd March 2022.pptException Handling on 22nd March 2022.ppt
Exception Handling on 22nd March 2022.ppt
 
Exception
ExceptionException
Exception
 
java.pptx
java.pptxjava.pptx
java.pptx
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handling
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
PROGRAMMING IN JAVA
PROGRAMMING IN JAVAPROGRAMMING IN JAVA
PROGRAMMING IN JAVA
 

More from Sireesh K

More from Sireesh K (20)

Cn10
Cn10Cn10
Cn10
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
What is mvc
What is mvcWhat is mvc
What is mvc
 
31c
31c31c
31c
 
31cs
31cs31cs
31cs
 
45c
45c45c
45c
 
44c
44c44c
44c
 
42c
42c42c
42c
 
40c
40c40c
40c
 
39c
39c39c
39c
 
38c
38c38c
38c
 
37c
37c37c
37c
 
35c
35c35c
35c
 
34c
34c34c
34c
 
33c
33c33c
33c
 
30c
30c30c
30c
 
29c
29c29c
29c
 
27c
27c27c
27c
 
28c
28c28c
28c
 

Recently uploaded

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

41c

  • 1. Hi friends C# Tutorial Part 41: ERROR www.siri-kt.blogspot.com
  • 2. • Errors refer to the mistake or faults which occur during program development or execution. If you don't find them and correct them, they cause a program to produce wrong results. • Types of Errors • In programming language errors can be divided into three categories as given below-
  • 3. • Syntax Errors: • Syntax errors occur during development, when you make type mistake in code. For example, instead of writing while, you write WHILE then it will be a syntax error since C# is a case sensitive language. • bool flag=true; • WHILE (flag) //syntax error, since c# is case sensitive • { • //TO DO: • }
  • 4. • Runtime Errors (Exceptions): • Runtime errors occur during execution of the program. These are also called exceptions. This can be caused due to improper user inputs, improper design logic or system errors. – int a = 5, b = 0; – int result = a / b; // DivideByZeroException • Exceptions can be handled by using try-catch blocks.
  • 5. • Logical Errors • Logic errors occur when the program is written fine but it does not produce desired result. Logic errors are difficult to find because you need to know for sure that the result is wrong • int a = 5, b = 6; • double avg = a + b / 2.0; // logical error, it should be (a + b) / 2.0
  • 6. • Exception Handling • Exception handling is a mechanism to detect and handle run time errors. It is achieved by using Try-Catch- Finally blocks and throw keyword. • Try block • The try block encloses the statements that might throw an exception. – try – { – // Statements that can cause exception. – }
  • 7. • the microsoft given 4 keywords for handling Runtime errors • 1.try • 2.catch • 3.finally • 4.Throw • if we are not expect any errors in an application then we can't work with exception handling. • syntax: • try • { expected error information } • catch • { exception information } • finally • { Result(o/p) } • throw • { user defined exception }
  • 8. • 1.try: • in the try block we have to include all expected exceptions statements. try block followed with cacth &finally,catch (or)finally one try block may having multiple catch blocks but having only one finally block. one try block raising only one exception at a time.one try block can executes one catch block at time • 2.catch: • using catch block we can provide exception information.one catch block can handles only one exception • 3.finally block: • the finally block executes which statements doesn't
  • 9. • 4.throw: • throw bloack can handle only one userdefined exception at a time. this block can handle multiple userdefined exceptions at a time. • example exception Handling: • static void Main(string[] args) • { try • { int a, b, c; • Console.WriteLine("enter a value"); • a=int.Parse(Console.ReadLine()); • Console.WriteLine("enter b value"); • b=int.Parse(Console.ReadLine()); • c = a / b; • Console.WriteLine(c.ToString()); • Console.ReadLine(); } • catch (Exception ex) • { Console.WriteLine(ex.ToString()); • Console.ReadLine(); }
  • 10. • ex2: • 1.take a form • 2.add 3 label,3 textboxes&one button • source code: • private void button1_Click(object sender, EventArgs e) • { int a, b, res = 0; • try • { a = Convert.ToInt16(textBox1.Text); • b = Convert.ToInt16(textBox2.Text); • res = a / b; } • catch (Exception ex) • { MessageBox.Show(ex.Message); } • finally • { textBox3.Text = res.ToString(); } }
  • 11. • Catch block • Catch block handles any exception if one exists. – catch(ExceptionType e) – { – // Statements to handle exception. – } • Finally block • The finally block can be used for doing any clean-up process like releasing unused resources even if an exception is thrown. For example, disposing database connection. – finally – { – // Statement to clean up. – }
  • 12. – Throw keyword – This keyword is used to throw an exception explicitly. – catch (Exception e) – { – throw (e); – }
  • 13. • Key points about exceptions handling • Exceptions are types that all directly or indirectly derive from System.Exception class. • Exception objects contain detailed information about the error, such as the state of the call stack and a text description of the error. • A try block is used to throw multiple exceptions that can handle by using multiple catch blocks. • More specialized catch block should come before a generalized one. Otherwise specialized catch block will never be executed. • Exceptions can be explicitly generated by a program by using the throw keyword.
  • 14. • If no exception handling mechanism is used, the program stops executing with an error message. • By providing a catch block without a brackets or arguments, we can catch all exceptions occurred inside a try block. – Catch – { Console.WriteLine("oException" ); } • By providing a catch block with an exception object, you can obtain more information about the type of exception that occurred. – catch(Exception e) – { Console.WriteLine(e.Message); } • The statements inside the finally block are always executed whether exception occurs or not in the program. • Also, before the termination of the program finally block is always executed.
  • 15. Order of Try-Catch-Finally blocks • In the order of exceptions handling blocks try block comes first, after that catch block(s) come and in the last finally block come. • try • { // statements that can cause exception. } • catch (MoreSpecificExceptionType e1) • { // error handling code } • catch (SpecificExceptionType e2) • { // error handling code } • catch (GeneralExceptionType eN) • { // error handling code } • finally • { // statement to clean up. }
  • 16. You can also skip finally block if required. • try • { // statements that can cause exception. } • catch (MoreSpecificExceptionType e1) • { // error handling code } • catch (SpecificExceptionType e2) • { // error handling code } • catch (GeneralExceptionType eN) • { // error handling code } • You can also skip catch block(s) if required. • try • { // statements that can cause exception. } • finally • { // statement to clean up. } • Hence a combination of try-catch-finally or try-catch or try-finally blocks is valid.
  • 17. For more visit our website www.siri-kt.blogspot.com Thanks for Watching More Angular JS TutorialsMore C sharp (c#) tutorials