[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Buckys C++ Programming Tutorials – 63 – More Exceptions Examples
by
Tags:
Comments
46 responses to “Buckys C++ Programming Tutorials – 63 – More Exceptions Examples”
-
nice work keep it up..:)
-
This wasn't that difficult
-
Gotta catch em All Pokemon!
-
I have tried a lot but haven't been successful. I have been trying for a long time to actually build a calculator. A calculator as in a calculator where u can add, subtract, multiply, divide. This much is enough. But I haven't been able to do this. I tried using classes, different functions but without success. And a bigger problem is that I can't use the "cin >> " thingy in classes yet, as in I tried to use it with the class objects but it shows error every time, otherwise I can use it. Someone help.
-
Yes I do want to know object exception handling.
-
it should have more sense like this: if (num2 == 0|| num1==0){ ..bla bla yati yati yati 😛
-
So if you were to throw several int errors with different corresponding messages, how do you catch them seperately? Say you also wanted to check for a negative number as well as zero, and have it display a new message for negative numbers. How would you do this? Also, thank you for this videos. They are so much more helpful than my teacher :/
-
LoL cool!
like the moment:
"let's go ahead and say that we have an idiot that's gonna you know neve knows how to use calculator and is going to try to divide by 0"
That's really funy moment!
Like sorta videos!!! -
I think this was the first program I've written that actually does something meaningful. Now I make a million dollars with my calculator
-
cool huh, pretty?
-
so what happens if i had to include two error types for int data type.like if you divide by 0 you get different catch but if you divide by -1 it tells you another different message . how to do that? we use catch(int x) which would take both 0 and -1 but i want different catch functions(?)
-
can you catch an auto type?
-
If i write throw "ERROR";
what to pass in catch(?????) -
the math gods will not allow it .
-
The return of "pretty cool huh"
-
10 MORE EPISODES GUYS!!
-
Well you could divide by zero in theory, this is why we have limits 😛
-
Or you can actually create exceptions just like the … but this time you can actually give it a variable name.. Explained here: https://github.com/amanuel2/C-Examples/blob/master/Files/Reading/partone/main.cpp
-
Just for the curious out here, deviding by zero will not blow up your computer!
(code to test)
int x = 10;
while (true) {
std::cout << 100 / x;
x–;
} -
Three dots is called variadic, functions can take multiple parameters by passing a variadic argument. Could mention #include <stdexcept>, throw exception vs catching an exception. Also maybe talk about the standard exception classes in C++ one could use to handle an exception.
-
it's confusing. I tried with catch (int x) instead of catch (…) but it return the same result
-
but how will I use multiple exception I created this and it's not working!!
#include <iostream>
#include <string>
using namespace std;int main()
{
try{int mom=39;
int son=18;
int daughter=15;if (son && daughter >mom){
throw 47;
}}
catch(int x){
cout<<"son and daughter can't be older than mom you moron!! "<<endl;}
if (son > mom){throw 37;
}
catch(int y)
{
cout<<"son can't be older than mom you moron!!"<<endl;
}if (daughter > mom ) {
throw 57;
}catch(int z) {
cout<<"daughter can't be older than mom you moron!!"<<endl;
}}
-
heres how to pass an exception class into main:
#include <iostream>
#include <stdexcept> // must include this directoryusing namespace std;
class whatexception : public exception
{
// leave empty for now for simplicity
};int main()
{try {
int i = 0;
if (i == 0)
{
throw whatexception();
}}catch (whatexception)
{
cout << " lol u got me , i == 0 " << endl;
}system("pause");
return 0;}
-
QUESTIONS:
1. Should all code be run inside the try block? Or is it better to input everything outside the try block, and only use the try block to check against various errors?2. What is the point of (…)? Isn't (int x) doing the same thing? catching all the errors, and placing their throw values in x?
3. Can you independently use a catch function without a try function? Would that even make sense? Could you have multiple catch blocks for a try block, to implement variable overloading or something?
4. And, lastly, how would you go about implementing a personalized message for each different error throw value? Is if-else-if inside the catch block the best way to go, or is there a better suited, more formalized way of doing it?
-
could you done a vid on inheritance from exception classes?
-
why can't we use IF ELSE instead ? isn't it the same ?
-
It seems that you can not get more than one catch per try , don't you?
-
if i use the catch(…) thing how can i still show the "x" number from the throw thing
-
cin was covered very quickly in 20 – Sentinel Controlled Program, Thanks Bucky for your great work on putting this play list together.
-
Wished viewers would stop using the comments section to say "thanks Bucky!" Instead of asking questions. It makes its harder for people to go thru all this rambling to get to actual questions. If you want to thank the uploaded please use YouTube's message feature. It's what it's there for. You people are the reason why YouTube needs exception handling.
-
Can you use templates with catch?
-
gotta catch em all
-
Do these exceptions have anything to do with why people don't like using the C++ Standard Library? I always here people don't like using it because it uses exceptions but I never understood what that meant. Can someone please clarify?
-
Pretty Cool HA xD damn Always
-
Does the catch(…) exist in Java as well?
-
The math gods will not allow it LOL
-
"dot dot dot" is commonly called the ellipsis.
-
Its called Varag Expression in Lua
-
can you catch a pointer or array?
-
It is good to know that you can use "(…)" in functions and the receive unnamed arguments. These arguments accessible with macros from the "stdarg.h" header. Nice tutorial.
-
catch em all !
-
great tutorial and explanation
-
This "dot dot dot" thingy means it is a 'variadic function'. That's what we call it.
Apart from that, good stuff man. -
Or you could not suggest people use goto's unnecessary, and put your whole try catch into a while(1) loop, with a break statement for when everything goes alright.
Which would be the structured way to handle this. Or, you could use a do while loop with a check for a flag to see if it went without a hitch, if it didn't, you'd just have it loop back. -
only 24000 views :O stay strong buddy we can make it 🙂
-
2 years old top comment. Jeeeez.
Leave a Reply