Commit 010aee55 by Patryk Czarnik

sprawdzanie zakresu get set i wyjątki tekstowe

parent 176a8212
...@@ -24,6 +24,15 @@ int main() { ...@@ -24,6 +24,15 @@ int main() {
std::cout <<"size: " << w.size() << '\n'; std::cout <<"size: " << w.size() << '\n';
std::cout << w << '\n'; std::cout << w << '\n';
// EXN w.set(50, 5050);
try {
w.set(50, 5050);
std::cout << "udało się ustawić element 50\n";
} catch(const char *exn) {
std::cout << "wyjątek " << exn << '\n';
}
std::cout << "Koniec programu\n"; std::cout << "Koniec programu\n";
return 0; return 0;
} }
...@@ -33,11 +33,16 @@ void Wektor::push_back(int e) { ...@@ -33,11 +33,16 @@ void Wektor::push_back(int e) {
} }
void Wektor::set(int idx, int e) { void Wektor::set(int idx, int e) {
// FIXME kontrola zakresu if(idx < 0 || idx >= liczba_elementow) {
throw "indeks poza zakresem";
}
t[idx] = e; t[idx] = e;
} }
int Wektor::get(int idx) { int Wektor::get(int idx) {
if(idx < 0 || idx >= liczba_elementow) {
throw "indeks poza zakresem";
}
return t[idx]; return t[idx];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment