Kod: |
[student] [~/rp4] > g++ error.cpp -o error
[student] [~/rp4] > error IOT trap [student] [~/rp4] > |
Kod: |
#include <iostream>
#include <string> #include <vector> using namespace std; class Greska { private: string text; public: Greska( const string &_text ) : text(_text) {}; string GetText() const { return text; } }; class Stupac { private: vector<string> podaci; public: void AddPodatak( const string ); string GetPodatak( const vector<string>::size_type ) const; }; void Stupac::AddPodatak( const string str ) { podaci.push_back( str ); } string Stupac::GetPodatak( const vector<string>::size_type i ) const { if( i >= podaci.size() || i < 0 ) throw new Greska( "Index out of bounds." ); return podaci[i]; } int main() { Stupac stupac; stupac.AddPodatak( "mirko" ); stupac.AddPodatak( "fodor" ); stupac.AddPodatak( "slavko" ); stupac.AddPodatak( "zeljko" ); try { cout << stupac.GetPodatak( 18 ); } catch( Greska e ) { cerr << e.GetText() << endl; } return 0; } |
Kod: |
throw new exception + catch exception*
ili throw exception + catch exception |
output generated using printer-friendly topic mod. Vremenska zona: GMT + 01:00.