Error Handling

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€88.87
List Price:  €124.43
You save:  €35.55
£75.15
List Price:  £105.22
You save:  £30.06
CA$139.41
List Price:  CA$195.18
You save:  CA$55.77
A$156.01
List Price:  A$218.42
You save:  A$62.41
S$129.82
List Price:  S$181.75
You save:  S$51.93
HK$777.79
List Price:  HK$1,088.94
You save:  HK$311.15
CHF 83.16
List Price:  CHF 116.43
You save:  CHF 33.26
NOK kr1,036.96
List Price:  NOK kr1,451.79
You save:  NOK kr414.82
DKK kr663.14
List Price:  DKK kr928.42
You save:  DKK kr265.28
NZ$169.15
List Price:  NZ$236.82
You save:  NZ$67.67
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.91
৳12,188.92
List Price:  ৳17,064.98
You save:  ৳4,876.05
₹8,540.13
List Price:  ₹11,956.53
You save:  ₹3,416.39
RM430.10
List Price:  RM602.16
You save:  RM172.06
₦160,694.92
List Price:  ₦224,979.32
You save:  ₦64,284.40
₨28,187.10
List Price:  ₨39,463.07
You save:  ₨11,275.97
฿3,296.66
List Price:  ฿4,615.46
You save:  ฿1,318.79
₺3,876.15
List Price:  ₺5,426.76
You save:  ₺1,550.61
B$565.35
List Price:  B$791.51
You save:  B$226.16
R1,819.79
List Price:  R2,547.79
You save:  R727.99
Лв173.65
List Price:  Лв243.12
You save:  Лв69.46
₩139,574.81
List Price:  ₩195,410.33
You save:  ₩55,835.51
₪354.19
List Price:  ₪495.88
You save:  ₪141.69
₱5,536.94
List Price:  ₱7,751.94
You save:  ₱2,214.99
¥14,536.09
List Price:  ¥20,351.11
You save:  ¥5,815.01
MX$1,944.15
List Price:  MX$2,721.88
You save:  MX$777.73
QR364.06
List Price:  QR509.70
You save:  QR145.64
P1,361.73
List Price:  P1,906.48
You save:  P544.74
KSh12,933.70
List Price:  KSh18,107.70
You save:  KSh5,174
E£5,061.53
List Price:  E£7,086.34
You save:  E£2,024.81
ብር13,459.34
List Price:  ብር18,843.61
You save:  ብር5,384.27
Kz91,190.88
List Price:  Kz127,670.88
You save:  Kz36,480
CLP$93,359.66
List Price:  CLP$130,707.26
You save:  CLP$37,347.60
CN¥722.46
List Price:  CN¥1,011.47
You save:  CN¥289.01
RD$5,902.61
List Price:  RD$8,263.89
You save:  RD$2,361.28
DA13,306.79
List Price:  DA18,630.04
You save:  DA5,323.25
FJ$227.15
List Price:  FJ$318.02
You save:  FJ$90.87
Q770.30
List Price:  Q1,078.46
You save:  Q308.15
GY$20,924.33
List Price:  GY$29,294.90
You save:  GY$8,370.57
ISK kr13,059.69
List Price:  ISK kr18,284.09
You save:  ISK kr5,224.40
DH926.13
List Price:  DH1,296.62
You save:  DH370.49
L1,709.38
List Price:  L2,393.20
You save:  L683.82
ден5,476.65
List Price:  ден7,667.53
You save:  ден2,190.88
MOP$801.19
List Price:  MOP$1,121.71
You save:  MOP$320.51
N$1,867.19
List Price:  N$2,614.14
You save:  N$746.95
C$3,690.56
List Price:  C$5,166.94
You save:  C$1,476.37
रु13,561.38
List Price:  रु18,986.48
You save:  रु5,425.09
S/365.16
List Price:  S/511.24
You save:  S/146.08
K405.78
List Price:  K568.11
You save:  K162.33
SAR375.06
List Price:  SAR525.10
You save:  SAR150.03
ZK2,781.79
List Price:  ZK3,894.63
You save:  ZK1,112.83
L454.99
List Price:  L637.01
You save:  L182.01
Kč2,217.63
List Price:  Kč3,104.78
You save:  Kč887.14
Ft35,921.40
List Price:  Ft50,291.40
You save:  Ft14,370
SEK kr971.07
List Price:  SEK kr1,359.54
You save:  SEK kr388.46
ARS$112,727.26
List Price:  ARS$157,822.68
You save:  ARS$45,095.41
Bs690.65
List Price:  Bs966.94
You save:  Bs276.29
COP$424,975.26
List Price:  COP$594,982.37
You save:  COP$170,007.10
₡50,658.12
List Price:  ₡70,923.39
You save:  ₡20,265.27
L2,602.65
List Price:  L3,643.81
You save:  L1,041.16
₲803,267.16
List Price:  ₲1,124,606.16
You save:  ₲321,338.99
$U4,177.30
List Price:  $U5,848.39
You save:  $U1,671.08
zł376.14
List Price:  zł526.62
You save:  zł150.47
Already have an account? Log In

Transcript

Hello, welcome to the 65th tutorial in the c++ programming series, and in this part we'll be looking at error handling. c++ provides a means to handle runtime errors called exceptions, which allow an error to be detected within a certain block of code and routing the flow to another piece of code if an Erica instead of crashing, for example, if you try to load a file, the application could pick up an error which file didn't exist, and inform the user that the Father exists. This is useful obviously, because you do not want your application to crash. You just provide an alternate alternate route for your application. And setting this example is going to tell the user what's happened. So let's go ahead and open up our project.

And we're not going to actually create a class in this one. First, I'm going to create a class for wild foods, food, few tutorials, and only so the syntax is the key word Troy. Basically Saying, let's try some code, then you put curly braces and then in here you put the code that you want for error handling. So it's going to pop fro one. And for one just basically throws an error. And the reason we're going to throw an error explicitly is so you can see what happened.

But otherwise, you'll put something in here and if it failed, then he will just get into the catch block which we're going to implement now. Catch basically catches the error which we are explicitly going to throw that we know that an error occur. We're just going to put it error and this error will actually be one. If we do STD STD, the error can do STD and line wrap and we get one and that's okay. And you're moving on They understand a little bit but let's just try and give you a better example. So if you have a variable save it or make it equal to no and then put it in the Troy if it is less than 10 then it's a okay so we can perform some function acting.

So what we could do is just we're just gonna print out so STD alone. As we could throw this exception, we run out, we get nine but if we change this to 11 when we get one here's another better example looking at implemented was going to talk me in Division you don't be blind but zero if you put that into a calculator prior to that if you're not on time, you'll get an error. If you're doing an application, and if your application doesn't have the proper error handling for whether it's via try, catch block, or whether it's something else, just simple if else statements, your application will crash, what you could do here is do a try. And if you get an error or some sort of problem, you will cache the error, and then you won't do the division. So that's a pretty cool thing that you can do.

And that's it for this part of the series. The next part we're going to look at preprocessor macro definitions. If you have any questions, feel free to message us at support at signal systems code at UK email will be in the description you can comment on this video with historically messages via YouTube, or calling for source code will also be in the description and as usual, thanks for watching and hope you have a great day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.