AIM:-Write a program to show the working mode of try, throw and catch blocks in C++. Procedure:- Exception handling is used to find the errors which occurs during run time or execution time such as data overflow , arithematic exceptions. Exception handling is done by three major blocks:- Try:- is used to store error causing programs. Throw:-is used to throw values whenever an exception occurs. Catch:-is used to catch the thrown values and also contain the problem solving code. In the program the condition is x is not equal to 2,if the condition is true then it will throw x and catch code will be executed whereas if the condition is not satisfied it will not throw and further calculations will take place. Program:- #include using namespace std; int main() { int a,b; cout<<"enter values of a and b \n"; cin>>a>>b; int x = a-b; try { if (x != 2) { cout <<" result (a/x)="<<a/x<<"\n"; } else { throw(x); } } catch (int i) { cout<<"exception caught:x="<<x<<"\n"; } cout <<"END"; return 0; } Result:- Enter values of a and b:- 4 and 2 Exception caught:- x=2..
AIM: To show the working mode of try ,throw and catch block in C++.
PROCEDURE: By using try, catch and throw i make this program. Try and catch block is referred as protected code . In this program i used two even number to check whether it is even or not .I have done this program inside the main function.
PROGRAM: #include using namespace std; int main() { int a,e,o; cout <<"enter any value of a:"; cin>>a; try { if(a%2==0) { cout<<"it is even:"; throw(e); } else { cout<<"it is odd:"; throw(o); } throw(a); } catch(int c) { cout<<"it is possible:"; return 0; } } OUTPUT: enter any value of a 42 it is even: enter any value of a 43 it is odd: RESULT: I have done my program successfully.
AIM : TO create a program to show the working mode of try, throw and catch blocks in C++. PROCEDURE : step 1 : Start the program. step 2 : Try block is intended to throw exceptions, which is followed by catch blocks. Only one try block. Step 3 : It is used to throw exceptions to exception handler i.e. it is used to communicate information about error. A throw expression accepts one parameter and that parameter is passed to handler. Step 4 : Catch block is intended to catch the error and handle the exception condition. We can have multiple catch blocks. Step 5 : End the program. PROGRAM : #include using namespace std; int main() { int x[3]={-1,2,}; for(int i=0;i<2;i++) { int ex=x[i]; try { if (ex > 0) throw x; else throw 'ex'; } catch (int ex) { cout << " Integer exception" ; } catch (char ex) { cout << " Character exception" ; } catch (...) { cout << "Special exception"; } } return 0; } Error : 0 Output : Integer exception Character exception. Result : I have successfully done my program.
AIM:write a program to show the working mode of try,catch and throw blocks in C++. PROCEDURE: EXCEPTION HANDLING is a mechanism that separates code that detects and handles exceptional circumstances from the rest of the program. It is built upon 3 keywords; 1) throw: a program that throws an exception. 2) catch: catches an exception with an exception handler 3) try :identifies a block of code for which particular exceptions will be activated. In this program the condition m is equal to -1,if the condition is true then it will throw m and catch code will be executed whereas if the condition is not satisfied it will not throw and further calculations will take place. #include using namespace std; int main() { char l,m; try { cout<<"enter two characters"; cin>>l>>m; if(m==-1) throw 1; cout<<"m="; } catch(char n) { cout<<"value is not possible"; } } RESULT: Enter two characters P q M= Error=0
AIM:write a program to show the working mode of try,catch and throw block in c++. Exception handling is a mechanism that separates code that detects and handles exceptional circumstances from the rest of your program.It works with the help of three blocks; Try: identifies a block of code for which particular exception will be activated. Throw: it throws an exception . Catch: it catches an exception. PROCEDURE: in the program the condition y=3,if the condition is true then it will throw the value y and catch code will be executed.whereas if the condition is false then it will not throw the value and further calculations will take place. #include using namespace std; int main() { int x,y; try { cout<<"enter two numbers"; cin>>x>>y; if(y==3) throw 3; cout<<"division"<<x/y; } catch(int a) { cout<<"division is not possible"; } } Result ; Enter two numbers 6 4 Division1 I have done my program successfully
AIM: To create a program working mode of try, throw and catch block in c++. PROCEDURE: • throw − A program throws an exception when a problem shows up. This is done using a throw keyword. • catch − A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception. • try − A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks. PROGRAM: #include using namespace std; int main() { int n1,n2,result; cout<<"enter 1st number:"; cin>>n1; cout<<"enter 2nd number:"; cin>>n2; try { if(n2==0) throw n2; else { result=n1/n2; cout<<"the result is:"; } } catch(int x) { cout<<"can't divide by:"<<x; } cout<<"end of program."; } ERROR: 0 OUTPUT: Enter 1st no:45 Enter 2nd no: 0 Can’t divided by:0 End of program.
AIM: Write a program to show the working mode of try, throw and catch blocks in C++. PROCEDURE: Exception handling is used to find the errors which doesnot appear in syntax error such as data overflow, arithematic exceptions. It is done by three blocks try, catch, throw. In this program I have created an exception using try and then calculated percentage and determined weather the student is fail or pass. PROGRAM: #include using namespace std; int main() {
int percent; cout<<"Get the student percentage \n"; cin>>percent; try { if(percent!=0&&percent<100) {
} OUTPUT: Enter student percentage 34 The detail is valid END OR Enter student percentage 0 Exception caught ERROR :0 I have done my program correctly.
AIM : TO create a program to show the working mode of try, throw and catch blocks in C++. Procedure: Exception handling is used to find the errors which occurs during run time or execution time such as data overflow , arithematic exceptions. Exception handling is done by three major blocks:- Try:- is used to store error causing programs. Throw:-is used to throw values whenever an exception occurs. Catch:-is used to catch the thrown values and also contain the problem solving code. In the program the condition is x is not equal to 2,if the condition is true then it will throw x and catch code will be executed whereas if the condition is not satisfied it will not throw and further calculations will take place. Program: #include using namespace std; int main() { float pi=3,14; float r,area; cout<<"Enter radius to calculate area of the circle"<<endl; cin<<r; try { if (r<0) throw"Negative radius not possible"; area= pi*r*r; } catch(char* ex) { cout<<"area is: "<<area; return 0; } Error: No error found. Output: Enter radius to calculate area of the circle 3 area is: 28.26 Result: This program execute successufully.
INTRODUCTION Hadoop and Apache Spark both are big-data frameworks, but direct comparison of Hadoop and Spark is difficult because they do many of the same things, but are also non-overlapping in some areas. Hadoop is essentially a distributed data infrastructure, It distributes massive data collections across multiple nodes within a cluster of commodity servers, which means you don't need to buy and maintain expensive custom hardware. It also indexes and keeps track of that data, enabling big-data processing and analytics far more effectively than was possible previously. Spark, on the other hand, is a data-processing tool that operates on those distributed data collections; it doesn't do distributed storage Hadoop have many components of modules that work together to create the Hadoop framework. The primary Hadoop framework modules are: · Hadoop Common · ...
Dear students, Here im uploading study materials chapter wise. Follow your material one by one and report me if you have any queries. Chapter 1: Introduction about System Programming Chapter 2: 1 pass and 2 Pass Assembler Assembler Chapter 3: Macro & Linker Chapter 4 Compiler
Dear students, Here I'm uploading study material for unit 3 and 4 Follow the material in sequence order. Post your queries if you have any. Transport Layer Part 1 Transport Layer Part 2 Network Layer Routing Protocol
AIM:-Write a program to show the working mode of try, throw and catch blocks in C++.
ReplyDeleteProcedure:-
Exception handling is used to find the errors which occurs during run time or execution time such as data overflow , arithematic exceptions.
Exception handling is done by three major blocks:-
Try:- is used to store error causing programs.
Throw:-is used to throw values whenever an exception occurs.
Catch:-is used to catch the thrown values and also contain the problem solving code.
In the program the condition is x is not equal to 2,if the condition is true then it will throw x and catch code will be executed whereas if the condition is not satisfied it will not throw and further calculations will take place.
Program:-
#include
using namespace std;
int main()
{
int a,b;
cout<<"enter values of a and b \n";
cin>>a>>b;
int x = a-b;
try
{
if (x != 2)
{
cout <<" result (a/x)="<<a/x<<"\n";
}
else
{
throw(x);
}
}
catch (int i)
{
cout<<"exception caught:x="<<x<<"\n";
}
cout <<"END";
return 0;
}
Result:-
Enter values of a and b:-
4 and 2
Exception caught:- x=2..
https://drive.google.com/open?id=1gRh1MwZDrGMGpLB9rnMu34rQaohqPJKD
AIM: To show the working mode of try ,throw and catch block in C++.
ReplyDeletePROCEDURE: By using try, catch and throw i make this program. Try and catch block is referred as protected code . In this program i used two even number to check whether it is even or not .I have done this program inside the main function.
PROGRAM:
#include
using namespace std;
int main()
{
int a,e,o;
cout <<"enter any value of a:";
cin>>a;
try
{
if(a%2==0)
{
cout<<"it is even:";
throw(e);
}
else
{
cout<<"it is odd:";
throw(o);
}
throw(a);
}
catch(int c)
{
cout<<"it is possible:";
return 0;
}
}
OUTPUT: enter any value of a 42
it is even:
enter any value of a 43
it is odd:
RESULT: I have done my program successfully.
AIM : TO create a program to show the working mode of try, throw and catch blocks in C++.
ReplyDeletePROCEDURE :
step 1 : Start the program.
step 2 : Try block is intended to throw exceptions, which is followed by catch blocks. Only one try block.
Step 3 : It is used to throw exceptions to exception handler i.e. it is used to communicate information about error. A throw expression accepts one parameter and that parameter is passed to handler.
Step 4 : Catch block is intended to catch the error and handle the exception condition. We can have multiple catch blocks.
Step 5 : End the program.
PROGRAM :
#include
using namespace std;
int main()
{
int x[3]={-1,2,};
for(int i=0;i<2;i++)
{
int ex=x[i];
try
{
if (ex > 0)
throw x;
else
throw 'ex';
}
catch (int ex)
{
cout << " Integer exception" ;
}
catch (char ex)
{
cout << " Character exception" ;
}
catch (...)
{
cout << "Special exception";
}
}
return 0;
}
Error : 0
Output :
Integer exception Character exception.
Result :
I have successfully done my program.
AIM:write a program to show the working mode of try,catch and throw blocks in C++.
ReplyDeletePROCEDURE:
EXCEPTION HANDLING is a mechanism that separates code that detects and handles exceptional circumstances from the rest of the program.
It is built upon 3 keywords;
1) throw: a program that throws an exception.
2) catch: catches an exception with an exception handler
3) try :identifies a block of code for which particular exceptions will be activated.
In this program the condition m is equal to -1,if the condition is true then it will throw m and catch code will be executed whereas if the condition is not satisfied it will not throw and further calculations will take place.
#include
using namespace std;
int main()
{
char l,m;
try
{
cout<<"enter two characters";
cin>>l>>m;
if(m==-1)
throw 1;
cout<<"m=";
}
catch(char n)
{
cout<<"value is not possible";
}
}
RESULT:
Enter two characters
P q
M=
Error=0
AIM:write a program to show the working mode of try,catch and throw block in c++.
ReplyDeleteException handling is a mechanism that separates code that detects and handles exceptional circumstances from the rest of your program.It works with the help of three blocks;
Try: identifies a block of code for which particular exception will be activated.
Throw: it throws an exception .
Catch: it catches an exception.
PROCEDURE: in the program the condition y=3,if the condition is true then it will throw the value y and catch code will be executed.whereas if the condition is false then it will not throw the value and further calculations will take place.
#include
using namespace std;
int main()
{
int x,y;
try
{
cout<<"enter two numbers";
cin>>x>>y;
if(y==3)
throw 3;
cout<<"division"<<x/y;
}
catch(int a)
{
cout<<"division is not possible";
}
}
Result ;
Enter two numbers 6
4
Division1
I have done my program successfully
AIM: To create a program working mode of try, throw and catch block in c++.
ReplyDeletePROCEDURE:
• throw − A program throws an exception when a problem shows up. This is done using a throw keyword.
• catch − A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.
• try − A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks.
PROGRAM:
#include
using namespace std;
int main()
{
int n1,n2,result;
cout<<"enter 1st number:";
cin>>n1;
cout<<"enter 2nd number:";
cin>>n2;
try
{
if(n2==0)
throw n2;
else
{
result=n1/n2;
cout<<"the result is:";
}
}
catch(int x)
{
cout<<"can't divide by:"<<x;
}
cout<<"end of program.";
}
ERROR: 0
OUTPUT: Enter 1st no:45
Enter 2nd no: 0
Can’t divided by:0
End of program.
AIM: Write a program to show the working mode of try, throw and catch blocks in C++.
ReplyDeletePROCEDURE: Exception handling is used to find the errors which doesnot appear in syntax error such as data overflow, arithematic exceptions.
It is done by three blocks try, catch, throw.
In this program I have created an exception using try and then calculated percentage and determined weather the student is fail or pass.
PROGRAM:
#include
using namespace std;
int main()
{
int percent;
cout<<"Get the student percentage \n";
cin>>percent;
try
{
if(percent!=0&&percent<100)
{
cout<<"The detail is valid \n ";
}
else
{
throw(percent);
}
}
catch(int m)
{
cout<<"exception caught "<<"\n";
}
cout<<"END";
return 0;
}
OUTPUT:
Enter student percentage
34
The detail is valid
END
OR
Enter student percentage
0
Exception caught
ERROR :0
I have done my program correctly.
AIM : TO create a program to show the working mode of try, throw and catch blocks in C++.
ReplyDeleteProcedure: Exception handling is used to find the errors which occurs during run time or execution time such as data overflow , arithematic exceptions.
Exception handling is done by three major blocks:-
Try:- is used to store error causing programs.
Throw:-is used to throw values whenever an exception occurs.
Catch:-is used to catch the thrown values and also contain the problem solving code.
In the program the condition is x is not equal to 2,if the condition is true then it will throw x and catch code will be executed whereas if the condition is not satisfied it will not throw and further calculations will take place.
Program:
#include
using namespace std;
int main()
{
float pi=3,14;
float r,area;
cout<<"Enter radius to calculate area of the circle"<<endl;
cin<<r;
try
{
if (r<0)
throw"Negative radius not possible";
area= pi*r*r;
}
catch(char* ex)
{
cout<<"area is: "<<area;
return 0;
}
Error: No error found.
Output: Enter radius to calculate area of the circle
3
area is: 28.26
Result: This program execute successufully.
Good to see this blog, waiting for more like this.
ReplyDeleteAzure Training in Chennai
Microsoft Azure Training in Chennai
Data Analytics Courses in Chennai
Big Data Analytics Courses in Chennai
DevOps course in Chennai
Best DevOps Training in Chennai
Azure Training in Anna Nagar
Azure Training in T Nagar