0

Why try catch doesn't work??

In my code I use try and catch block in floodFill function but it doesn't catch the eventualy exception caused by the second else if statment... Thank. https://code.sololearn.com/cMqY3KG49ORr/?ref=app

23rd Jun 2017, 9:16 PM
clement
clement - avatar
4 Respostas
0
The [] operator does not throw exceptions, so there is nothing to be caught. If you want it to throw use at instead: layer.at(x + xp).at(y + yp). Looks uglier in my opinion so I prefer doing the bounds checking myself. http://www.cplusplus.com/reference/vector/vector/operator[]/ Sadly the link doesn't work correctly ^^ Exception safety: If the container size is greater than n, the function never throws exceptions (no-throw guarantee). Otherwise, the behavior is undefined.
23rd Jun 2017, 10:27 PM
Dennis
Dennis - avatar
0
Thznk you man it work !! Yes it catches when values are < 0. Do you think I should raise an exception (with throw I guess) if x + px > vector size ? Thank you again bro !!
24th Jun 2017, 6:52 AM
clement
clement - avatar
0
You can do that, but I think it's better to just check if they are in bounds before accessing.
24th Jun 2017, 6:59 AM
Dennis
Dennis - avatar
0
Yes it is but now it's done, I don't touch it anymore :p Thank again
24th Jun 2017, 8:12 AM
clement
clement - avatar