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
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.
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 !!
0
You can do that, but I think it's better to just check if they are in bounds before accessing.
0
Yes it is but now it's done, I don't touch it anymore :p Thank again