SlideShare a Scribd company logo
Exception Handling
Exception Handling in .net
 Exceptions are types that all ultimately derive
from System.Exception.
 Use a try block around the statements that might throw
exceptions.
 Once an exception occurs in the try block, the flow of
control jumps to the first associated exception handler
that is present anywhere in the call stack. In C#,
the catch keyword is used to define an exception
handler.
 If no exception handler for a given exception is present,
the program stops executing with an error message.
Syntax
try {
// code that requires common cleanup or
// exception-recovery operations
}
catch (InvalidOperationException) {
//code that recovers from an InvalidOperationException
// (or any exception type derived from it)
}
catch (SomeOtherException) {
// code that recovers from an SomeOtherException
// (or any exception type derived from it)
}
catch {
// code that recovers from any kind of exception
// when you catch any exception, you usually re-throw
throw;
}
finally {
// code that cleans up any operations started
// within the try block. This code ALWAYS executes.
}
try block
 A try block contains code that requires common
cleanup or exception-recovery operations.
 The cleanup code should be put in a single finally
block.
 The exception recovery code should be put in one or
more catch blocks.
 Create one catch block for each kind of type you want
to handle.
 A try block must have at least one catch or finally
block.
catch block
 A catch block contains code to execute in response to an exception.
 If the code in a try block doesn’t cause an exception to be thrown, the CLR
will never execute the code in any of its catch blocks.
 You may or may not specify a catch type in parantheses after catch :
 The catch type must be of type System.Exception or a type that derived
from System.Exception
 If there is no catch type specified, that catch block handles any exception.
This is equivalent to having a catch block that specifies System.Exception
as a catch type.
 CLR searches for a matching catch type from top to bottom.
 If CLR cannot find any catch type that matches the exception, CLR
continues searching up the callstack to find a catch type.
 Once the catch block that matches the exception is found,
you have 3 choices:
 Re-throw the same exception
 Throw a different exception, giving richer exception
information to code.
 Let the code continue from the bottom of the catch block
 In choices 1-2, an exception is thrown and code starts
looking for a catch block whose type matches the
exception thrown
 In choice 3, the finally block is executed
 You can also specify a variable name like
catch(Exception e) to access information specific to the
exception.
finally block
 GC does automatic memory clean-up, it only cleans up if there are no
references kept on the object.
 Thus, memory leaks can occur if programmers carelessly keep references to
unwanted objects.
 C# provides the finally block, which is guaranteed to execute regardless of
whether an exception occurs.
 If the try block executes without throwing, the finally block executes.
 If the try block throws an exception, the finally block still executes
regardless of whether the exception is caught.
 This makes the finally block ideal to release resources from the
corresponding try block.
 Exception Classes in C#
 C# exceptions are represented by classes. The exception
classes in C# are mainly directly or indirectly derived from
the System.Exception class. Some of the exception classes
derived from the System.Exception class are
the System.ApplicationException and System.SystemE
xception classes.
 The System.ApplicationException class supports
exceptions generated by application programs. So the
exceptions defined by the programmers should derive from
this class.
 The System.SystemException class is the base class for all
predefined system exception.
System.Exception Properties
 Class Exception’s properties are used to formulate error messages
indicating a caught exception.
 Property Message stores the error message associated with an Exception
object.
 Property StackTrace contains a string that represents the method-call
stack.
 When an exception occurs, a programmer might use a different error
message or indicate a new exception type.
 The original exception object is stored in the InnerException property.
 Other properties:
 HelpLink specifies the location of a help file that describes the problem.
 Source specifies the name of the application or object that caused the
exception.
 TargetSite specifies the method where the exception originated.
Defined Exception
Exception Class Description
System.IO.IOException Handles I/O errors.
System.IndexOutOfRangeException Handles errors generated when a method refers to an array index
out of range.
System.ArrayTypeMismatchException Handles errors generated when type is mismatched with the array
type.
System.NullReferenceException Handles errors generated from deferencing a null object.
System.DivideByZeroException Handles errors generated from dividing a dividend with zero.
System.InvalidCastException Handles errors generated during typecasting.
System.OutOfMemoryException Handles errors generated from insufficient free memory.
System.StackOverflowException Handles errors generated from stack overflow.
Questions ??

More Related Content

What's hot

Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
Bharath K
 
Exception handling in c
Exception handling in cException handling in c
Exception handling in cMemo Yekem
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
Abinaya B
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
parag
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
Md. Tanvir Hossain
 
Java review: try catch
Java review: try catchJava review: try catch
Java review: try catch
Muzahidul Islam
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
ARAFAT ISLAM
 
Z blue exception
Z blue   exceptionZ blue   exception
Z blue exception
Narayana Swamy
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
Shipra Swati
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
ravinderkaur165
 
130410107010 exception handling
130410107010 exception handling130410107010 exception handling
130410107010 exception handling
Hemant Chetwani
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling
Exception handling Exception handling
Exception handling
M Vishnuvardhan Reddy
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
saman Iftikhar
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Adil Mehmoood
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
yugandhar vadlamudi
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
Nahian Ahmed
 

What's hot (20)

Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Exception handling in c
Exception handling in cException handling in c
Exception handling in c
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
 
Exceptions handling notes in JAVA
Exceptions handling notes in JAVAExceptions handling notes in JAVA
Exceptions handling notes in JAVA
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Java review: try catch
Java review: try catchJava review: try catch
Java review: try catch
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Z blue exception
Z blue   exceptionZ blue   exception
Z blue exception
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
 
17 exceptions
17   exceptions17   exceptions
17 exceptions
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
130410107010 exception handling
130410107010 exception handling130410107010 exception handling
130410107010 exception handling
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Exception handling
Exception handling Exception handling
Exception handling
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 

Viewers also liked

Csphtp1 23
Csphtp1 23Csphtp1 23
Csphtp1 23
HUST
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10
HUST
 
Csphtp1 05
Csphtp1 05Csphtp1 05
Csphtp1 05
HUST
 
Csphtp1 15
Csphtp1 15Csphtp1 15
Csphtp1 15
HUST
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08
HUST
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
HUST
 
Apparel 2 chap 08
Apparel 2   chap 08Apparel 2   chap 08
Apparel 2 chap 08mrschapman
 
Web2.0 guide by_twlog
Web2.0 guide by_twlogWeb2.0 guide by_twlog
Web2.0 guide by_twlogtwdanny
 

Viewers also liked (8)

Csphtp1 23
Csphtp1 23Csphtp1 23
Csphtp1 23
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10
 
Csphtp1 05
Csphtp1 05Csphtp1 05
Csphtp1 05
 
Csphtp1 15
Csphtp1 15Csphtp1 15
Csphtp1 15
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
Apparel 2 chap 08
Apparel 2   chap 08Apparel 2   chap 08
Apparel 2 chap 08
 
Web2.0 guide by_twlog
Web2.0 guide by_twlogWeb2.0 guide by_twlog
Web2.0 guide by_twlog
 

Similar to 3.C#

Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
Abid Kohistani
 
Presentation1
Presentation1Presentation1
Presentation1
Anul Chaudhary
 
Exception Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLRException Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLRKiran Munir
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertionRakesh Madugula
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
DevaKumari Vijay
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
Ashwin Shiv
 
Exception handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread ProgrammingException handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread Programming
Prabu U
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
DrHemlathadhevi
 
Exception Handling
Exception HandlingException Handling
Exception Handling
Sunil OS
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
AKSHAYBHABAD5
 
Exceptions & Its Handling
Exceptions & Its HandlingExceptions & Its Handling
Exceptions & Its HandlingBharat17485
 
Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024
kashyapneha2809
 
Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024
nehakumari0xf
 
MODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docxMODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docx
VeerannaKotagi1
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Chapter13 exception handling
Chapter13 exception handlingChapter13 exception handling
Chapter13 exception handling
Prabhakar Nallabolu
 

Similar to 3.C# (20)

Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 
Presentation1
Presentation1Presentation1
Presentation1
 
Exception Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLRException Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLR
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertion
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
 
Java exceptions
Java exceptionsJava exceptions
Java exceptions
 
Java unit3
Java unit3Java unit3
Java unit3
 
Exception handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread ProgrammingException handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread Programming
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
 
Exceptions & Its Handling
Exceptions & Its HandlingExceptions & Its Handling
Exceptions & Its Handling
 
Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024
 
Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024
 
MODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docxMODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docx
 
java exception.pptx
java exception.pptxjava exception.pptx
java exception.pptx
 
summarizer16fev16_Exceptions
summarizer16fev16_Exceptionssummarizer16fev16_Exceptions
summarizer16fev16_Exceptions
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Chapter13 exception handling
Chapter13 exception handlingChapter13 exception handling
Chapter13 exception handling
 

More from Raghu nath

Mongo db
Mongo dbMongo db
Mongo db
Raghu nath
 
Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)
Raghu nath
 
Javascript part1
Javascript part1Javascript part1
Javascript part1Raghu nath
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaghu nath
 
Selection sort
Selection sortSelection sort
Selection sortRaghu nath
 
Binary search
Binary search Binary search
Binary search Raghu nath
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)Raghu nath
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithmsRaghu nath
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp roleRaghu nath
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4Raghu nath
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3Raghu nath
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2Raghu nath
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1Raghu nath
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1Raghu nath
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 

More from Raghu nath (20)

Mongo db
Mongo dbMongo db
Mongo db
 
Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)
 
MS WORD 2013
MS WORD 2013MS WORD 2013
MS WORD 2013
 
Msword
MswordMsword
Msword
 
Ms word
Ms wordMs word
Ms word
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Selection sort
Selection sortSelection sort
Selection sort
 
Binary search
Binary search Binary search
Binary search
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithms
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp role
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Perl
PerlPerl
Perl
 

Recently uploaded

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 

Recently uploaded (20)

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 

3.C#

  • 2. Exception Handling in .net  Exceptions are types that all ultimately derive from System.Exception.  Use a try block around the statements that might throw exceptions.  Once an exception occurs in the try block, the flow of control jumps to the first associated exception handler that is present anywhere in the call stack. In C#, the catch keyword is used to define an exception handler.  If no exception handler for a given exception is present, the program stops executing with an error message.
  • 3. Syntax try { // code that requires common cleanup or // exception-recovery operations } catch (InvalidOperationException) { //code that recovers from an InvalidOperationException // (or any exception type derived from it) } catch (SomeOtherException) { // code that recovers from an SomeOtherException // (or any exception type derived from it) } catch { // code that recovers from any kind of exception // when you catch any exception, you usually re-throw throw; } finally { // code that cleans up any operations started // within the try block. This code ALWAYS executes. }
  • 4. try block  A try block contains code that requires common cleanup or exception-recovery operations.  The cleanup code should be put in a single finally block.  The exception recovery code should be put in one or more catch blocks.  Create one catch block for each kind of type you want to handle.  A try block must have at least one catch or finally block.
  • 5. catch block  A catch block contains code to execute in response to an exception.  If the code in a try block doesn’t cause an exception to be thrown, the CLR will never execute the code in any of its catch blocks.  You may or may not specify a catch type in parantheses after catch :  The catch type must be of type System.Exception or a type that derived from System.Exception  If there is no catch type specified, that catch block handles any exception. This is equivalent to having a catch block that specifies System.Exception as a catch type.  CLR searches for a matching catch type from top to bottom.  If CLR cannot find any catch type that matches the exception, CLR continues searching up the callstack to find a catch type.
  • 6.  Once the catch block that matches the exception is found, you have 3 choices:  Re-throw the same exception  Throw a different exception, giving richer exception information to code.  Let the code continue from the bottom of the catch block  In choices 1-2, an exception is thrown and code starts looking for a catch block whose type matches the exception thrown  In choice 3, the finally block is executed  You can also specify a variable name like catch(Exception e) to access information specific to the exception.
  • 7. finally block  GC does automatic memory clean-up, it only cleans up if there are no references kept on the object.  Thus, memory leaks can occur if programmers carelessly keep references to unwanted objects.  C# provides the finally block, which is guaranteed to execute regardless of whether an exception occurs.  If the try block executes without throwing, the finally block executes.  If the try block throws an exception, the finally block still executes regardless of whether the exception is caught.  This makes the finally block ideal to release resources from the corresponding try block.
  • 8.  Exception Classes in C#  C# exceptions are represented by classes. The exception classes in C# are mainly directly or indirectly derived from the System.Exception class. Some of the exception classes derived from the System.Exception class are the System.ApplicationException and System.SystemE xception classes.  The System.ApplicationException class supports exceptions generated by application programs. So the exceptions defined by the programmers should derive from this class.  The System.SystemException class is the base class for all predefined system exception.
  • 9. System.Exception Properties  Class Exception’s properties are used to formulate error messages indicating a caught exception.  Property Message stores the error message associated with an Exception object.  Property StackTrace contains a string that represents the method-call stack.  When an exception occurs, a programmer might use a different error message or indicate a new exception type.  The original exception object is stored in the InnerException property.  Other properties:  HelpLink specifies the location of a help file that describes the problem.  Source specifies the name of the application or object that caused the exception.  TargetSite specifies the method where the exception originated.
  • 10. Defined Exception Exception Class Description System.IO.IOException Handles I/O errors. System.IndexOutOfRangeException Handles errors generated when a method refers to an array index out of range. System.ArrayTypeMismatchException Handles errors generated when type is mismatched with the array type. System.NullReferenceException Handles errors generated from deferencing a null object. System.DivideByZeroException Handles errors generated from dividing a dividend with zero. System.InvalidCastException Handles errors generated during typecasting. System.OutOfMemoryException Handles errors generated from insufficient free memory. System.StackOverflowException Handles errors generated from stack overflow.