This document discusses exception handling in C++. It begins with an introduction explaining that exception handling allows a program to automatically invoke error handling routines when runtime errors occur. It then covers key aspects of exception handling including the try, catch, and throw statements. Finally, it provides code examples demonstrating how to throw, catch, and handle exceptions in C++.
A JavaScript function is a block of code designed to perform a particular task.
Why Functions?
You can reuse code: Define the code once, and use it many times. You can use the same code many times with different arguments, to produce different results.
What is the DOM?
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."
The W3C DOM standard is separated into 3 different parts:
Core DOM - standard model for all document types
XML DOM - standard model for XML documents
HTML DOM - standard model for HTML documents
The HTML DOM (Document Object Model)
When a web page is loaded, the browser creates a Document Object Model of the page.
The HTML DOM model is constructed as a tree of Objects.
With the HTML DOM, JavaScript can access and change all the elements of an HTML document.
A JavaScript function is a block of code designed to perform a particular task.
Why Functions?
You can reuse code: Define the code once, and use it many times. You can use the same code many times with different arguments, to produce different results.
What is the DOM?
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."
The W3C DOM standard is separated into 3 different parts:
Core DOM - standard model for all document types
XML DOM - standard model for XML documents
HTML DOM - standard model for HTML documents
The HTML DOM (Document Object Model)
When a web page is loaded, the browser creates a Document Object Model of the page.
The HTML DOM model is constructed as a tree of Objects.
With the HTML DOM, JavaScript can access and change all the elements of an HTML document.
If you are using jQuery, you need to understand the Document Object Model and how it accounts for all the elements inside any HTML document or Web page.
JavaScript Events:
HTML events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events.
What can JavaScript Do?
Event handlers can be used to handle, and verify, user input, user actions, and browser actions:
Things that should be done every time a page loads
Things that should be done when the page is closed
Action that should be performed when a user clicks a button
Content that should be verified when a user inputs data
Threads And Synchronization in C#
Concept about Threads And Synchronization in C#
it will help you about this concept
feel free
Download free programming applications on
http://www.androidapplications.xyz
Abstraction in c++ and Real Life Example of Abstraction in C++Hitesh Kumar
Abstraction in c++ and Real Life Example of Abstraction in C++ - Abstraction is one of the features of Object-Oriented Programming, where you show only relevant details to the user and hide irrelevant details.
If you are using jQuery, you need to understand the Document Object Model and how it accounts for all the elements inside any HTML document or Web page.
JavaScript Events:
HTML events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events.
What can JavaScript Do?
Event handlers can be used to handle, and verify, user input, user actions, and browser actions:
Things that should be done every time a page loads
Things that should be done when the page is closed
Action that should be performed when a user clicks a button
Content that should be verified when a user inputs data
Threads And Synchronization in C#
Concept about Threads And Synchronization in C#
it will help you about this concept
feel free
Download free programming applications on
http://www.androidapplications.xyz
Abstraction in c++ and Real Life Example of Abstraction in C++Hitesh Kumar
Abstraction in c++ and Real Life Example of Abstraction in C++ - Abstraction is one of the features of Object-Oriented Programming, where you show only relevant details to the user and hide irrelevant details.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
2. Contents
13.1 Exception Handling Fundamentals
13.2 The try Block, the catch Exception Handler
13.3 The throw Statements
13.4 The try/throw/catch sequence
13.5 Exception Specification
13.6 Unexpected Exception
13.7 Catch – All Exception Handlers
13.8 Throwing an exception from handler
13.9 Uncaught Exception
2 By:-Gourav Kottawar
3. 3
Syntax Errors, Runtime Errors, and Logic
Errors
three categories of errors:
syntax errors, runtime errors, and logic
errors.
Syntax errors arise because the rules of the
language have not been followed. They are
detected by the compiler.
Runtime errors occur while the program is
running if the environment detects an operation
that is impossible to carry out.
Logic errors occur when a program doesn'tBy:-Gourav Kottawar
4. Introduction
Allows to manage run time errors
Using exception handling program can
invoke automatically invoke an error
handling routine when an error occurs.
Automates error handling code.
4 By:-Gourav Kottawar
5. 13.1 Exception Handling Fundamentals
Based on three try , catch and throw
Code that we want to monitor for exceptions must
have been executed from within try block.
Functions called from try block may also throw an
exception.
Exception that can be thrown by the monitored
code are caught by a catch statement.
5 By:-Gourav Kottawar
10. // This example will not work.
#include <iostream>
using namespace std;
int main()
{
cout << "Startn";
try { // start a try block
cout << "Inside try blockn";
throw 100; // throw an error
cout << "This will not execute";
}
catch (double i) { // won't work for an int
exception
cout << "Caught an exception -- value is: ";
cout << i << "n";
}
cout << "End";
return 0;
}
Start
Inside try block
Abnormal program
termination
10 By:-Gourav Kottawar
11. An exception can be thrown from outside the try block as long
as it is thrown by a function that is called from within try
block./* Throwing an exception from a
function outside the try block.
*/
#include <iostream>
using namespace std;
void Xtest(int test)
{
cout << "Inside Xtest, test is: " << test
<< "n";
if(test) throw test;
}
int main()
{
cout << "Startn";
try { // start a try block
cout << "Inside try blockn";
Xtest(0);
Xtest(1);
Xtest(2);
}
catch (int i) { // catch an error
cout << "Caught an exception --
value is: ";
cout << i << "n";
}
cout << "End";
return 0;
}
11 By:-Gourav Kottawar
12. An exception can be thrown from outside the try block as long
as it is thrown by a function that is called from within try
block./* Throwing an exception from a
function outside the try block.
*/
#include <iostream>
using namespace std;
void Xtest(int test)
{
cout << "Inside Xtest, test is: " << test
<< "n";
if(test) throw test;
}
int main()
{
cout << "Startn";
try { // start a try block
cout << "Inside try blockn";
Xtest(0);
Xtest(1);
Xtest(2);
}
catch (int i) { // catch an error
cout << "Caught an exception --
value is: ";
cout << i << "n";
}
cout << "End";
return 0;
} Start
Inside try block
Inside Xtest, test is: 0
Inside Xtest, test is: 1
Caught an exception -- value is: 1
End
12 By:-Gourav Kottawar
13. A try block can be localized to a function. When this is the case,
each time the function is entered, the exception handling relative to that
function is reset.
#include <iostream>
using namespace std;
// Localize a try/catch to a function.
void Xhandler(int test)
{
try{
if(test) throw test;
}
catch(int i) {
cout << "Caught Exception #: " << i <<
'n';
}
}
int main()
{
cout << "Startn";
Xhandler(1);
Xhandler(2);
Xhandler(0);
Xhandler(3);
cout << "End";
return 0;
}
13 By:-Gourav Kottawar
14. A try block can be localized to a function. When this is the case,
each time the function is entered, the exception handling relative to that
function is reset.
#include <iostream>
using namespace std;
// Localize a try/catch to a function.
void Xhandler(int test)
{
try{
if(test) throw test;
}
catch(int i) {
cout << "Caught Exception #: " << i <<
'n';
}
}
int main()
{
cout << "Startn";
Xhandler(1);
494 C + + : T h e C o m p l e
t e R e f e r e n c e
Xhandler(2);
Xhandler(0);
Xhandler(3);
cout << "End";
return 0;
}This program displays this
output:
Start
Caught Exception #: 1
Caught Exception #: 2
Caught Exception #: 314 By:-Gourav Kottawar
15. a catch statement will be executed only if it catches an exception. Otherwise,
execution simply bypasses the catch altogether.
#include <iostream.h>
int main()
{
cout << "Startn";
try { // start a try block
cout << "Inside try blockn";
cout << "Still inside try blockn";
}
catch (int i) { // catch an error
cout << "Caught an exception -- value is:
";
cout << i << "n";
}
C h a p t e r 1 9 : E x c e p t i o n H a n d l
i n g 495
cout << "End";
return 0;
}
Start
Inside try block
Still inside try block
End
the catch statement is bypassed by the flow of
execution
15 By:-Gourav Kottawar
16. Catching Class Types
Exception can be of any type.
Mostly it is user defined type. i.e. class
the most common reason that you will want to
define a class type for an exception is to create
an object that describes the error that occurred.
This information can be used by the exception
handler to help it process the error.
16 By:-Gourav Kottawar
17. // Catching class type
exceptions.
#include <iostream.h>
#include <cstring.h>
class MyException {
public:
char str_what[80];
int what;
MyException()
{
*str_what = 0; what = 0;
}
MyException(char *s, int e)
{
strcpy(str_what, s);
what = e;
}
};
int main()
{
int i;
try {
cout << "Enter a positive number:
";
cin >> i;
if(i<0)
throw MyException("Not
Positive", i);
}
catch (MyException e) { // catch
an error
cout << e.str_what << ": ";
cout << e.what << "n";
}
return 0;
}
17 By:-Gourav Kottawar
18. // Catching class type
exceptions.
#include <iostream.h>
#include <cstring.h>
class MyException {
public:
char str_what[80];
int what;
MyException()
{
*str_what = 0; what = 0;
}
MyException(char *s, int e)
{
strcpy(str_what, s);
what = e;
}
};
int main()
{
int i;
try {
cout << "Enter a positive number:
";
cin >> i;
if(i<0)
throw MyException("Not
Positive", i);
}
catch (MyException e) { // catch
an error
cout << e.str_what << ": ";
cout << e.what << "n";
}
return 0;
}
Enter a positive number: -4
Not Positive: -4
18 By:-Gourav Kottawar
24. // This example uses catch(...) as a
default.
#include <iostream.h>
void Xhandler(int test)
{
try{
if(test==0) throw test; // throw int
if(test==1) throw 'a'; // throw char
if(test==2) throw 123.23; // throw
double
}
catch(int i) { // catch an int
exception
cout << "Caught an integern";
}
catch(...) { // catch all other
exceptions
cout << "Caught One!n";
}
}
int main()
{
cout << "Startn";
Xhandler(0);
Xhandler(1);
Xhandler(2);
cout << "End";
return 0;
//output
Start
Caught an integer
Caught One!
Caught One!
End
24 By:-Gourav Kottawar
25. Restricting Exceptions
You can restrict the type of exceptions that a function can
throw outside of itself.
you can also prevent a function from throwing any
exceptions whatsoever.
To accomplish these restrictions, you must add a throw
clause to a function definition.
The general form of this is shown here:
ret-type func-name(arg-list) throw(type-list)
{
// ...
}
only those data types contained in the comma-separated
type-list may be thrown by the function.
25 By:-Gourav Kottawar
26. Throwing any other type of expression will cause
abnormal program
termination.
If you don't want a function to be able to throw
any exceptions, then use an empty list.
Attempting to throw an exception that is not
supported by a function will cause the standard
library function unexpected() to be called.
By default, this causes abort() to be called, which
causes abnormal program termination.
26 By:-Gourav Kottawar
27. // Restricting function throw types.
#include <iostream.h>
// This function can only throw ints,
chars, and doubles.
void Xhandler(int test) throw(int, char,
double)
{
if(test==0) throw test; // throw int
if(test==1) throw 'a'; // throw char
if(test==2) throw 123.23; // throw double
}
int main()
{
cout << "startn";
try{
Xhandler(0); // also, try passing 1 and 2
to Xhandler()
}
catch(int i) {
cout << "Caught an integern";
}
catch(char c)
{
cout << "Caught charn";
}
catch(double d) {
cout << "Caught
doublen";
}
cout << "end";
return 0;
}
27 By:-Gourav Kottawar
28. Rethrowing an Exception
We can rethrow exception using throw, by itself,
with no exception. This causes the current
exception to be passed on to an outer try/catch
sequence.
The most likely reason for doing so is to allow
multiple handlers access to the exception.
An exception can only be rethrown from within a
catch block (or from any function called from
within that block).
When you rethrow an exception, it will not be
recaught by the same catch statement. It will
propagate outward to the next catch
statement.28 By:-Gourav Kottawar
31. Understanding terminate( ) and unexpected(
)
terminate() and unexpected() are called when
something goes wrong during the exception
handling process.
These functions are supplied by the Standard C++
library.
Their prototypes are shown here:
void terminate( );
void unexpected( );
These functions require the header <exception>.
The terminate() function is called whenever the
exception handling subsystem fails to find a
matching catch statement for an exception.
It is also called if your program attempts to rethrow
an exception when no exception was originally
thrown.
31 By:-Gourav Kottawar
32. Understanding terminate( ) and unexpected( )
The terminate() function is also called under
various other, more obscure circumstances.
In general, terminate() is the handler of last
resort when no other handlers for an exception
are available. By default, terminate() calls
abort() .
The unexpected() function is called when a
function attempts to throw an exception that is
not allowed by its throw list. By default,
unexpected() calls terminate() .
32 By:-Gourav Kottawar
33. Setting the Terminate and Unexpected Handlers
The terminate() and unexpected() functions halt program
execution when an exception handling error occurs. However,
you can change the functions that are called by terminate()
and unexpected() .
program to take full control of the exception handling
subsystem.
To change the terminate handler, use set_terminate()
terminate_handler set_terminate(terminate_handler newhandler)
throw( );
Here newhandler is a pointer to the new terminate handler. The
function returns a
pointer to the old terminate handler.
The new terminate handler must be of type terminate_handler,
which is defined like this:
typedef void (*terminate_handler) ( );
33 By:-Gourav Kottawar
34. To change the unexpected handler, use
set_unexpected() , shown here:
unexpected_handler
set_unexpected(unexpected_handler newhandler) throw( );
newhandler is a pointer to the new unexpected handler. The
function returns a
pointer to the old unexpected handler. The new unexpected
handler must be of type unexpected_handler, which is
defined like this:
typedef void (*unexpected_handler) ( );
This handler may itself throw an exception, stop the program, or
call terminate() .
However, it must not return to the program.
Both set_terminate() and set_unexpected() require the header
<exception>.
34 By:-Gourav Kottawar
35. #include <cstdlib>
#include <exception>
using namespace std;
void my_Thandler()
{
cout << "Inside new
terminate handlern";
abort();
}
int main()
{
// set a new terminate handler
set_terminate(my_Thandler);
try {
cout << "Inside try blockn";
throw 100; // throw an error
}
catch (double i) { // won't catch
an int exception
// ...
}
return 0;
}
35 By:-Gourav Kottawar
36. #include <cstdlib>
#include <exception>
using namespace std;
void my_Thandler()
{
cout << "Inside new
terminate handlern";
abort();
}
int main()
{
// set a new terminate handler
set_terminate(my_Thandler);
try {
cout << "Inside try blockn";
throw 100; // throw an error
}
catch (double i) { // won't catch
an int exception
// ...
}
return 0;
}
The output from this program
is shown here.
Inside try block
Inside new terminate handler
abnormal program termination36 By:-Gourav Kottawar
37. The uncaught_exception( ) Function
The C++ exception handling subsystem
supplies one other function that you may
finduseful: uncaught_exception() .
Its prototype is shown here:
bool uncaught_exception( );
This function returns true if an exception has
been thrown but not yet caught.
Once caught, the function returns false.
37 By:-Gourav Kottawar