Skip to content

Commit 16a47e5

Browse files
authored
Merge pull request #110 from fnc12/feature/error-code-instead-of-runtime-error
Feature/error code instead of runtime error
2 parents 694d876 + 8ec2711 commit 16a47e5

7 files changed

Lines changed: 107 additions & 108 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ for(auto &user : storage.iterate<User>()) {
192192

193193
`iterate` member function returns adapter object that has `begin` and `end` member functions returning iterators that fetch object on dereference operator call.
194194

195-
CRUD functions `get`, `get_no_throw`, `remove`, `update` (not `insert`) work only if your type has a primary key column. If you try to `get` an object that is mapped to your storage but has no primary key column a `std::error_code` will be thrown cause `sqlite_orm` cannot detect an id. If you want to know how to perform a storage without primary key take a look at `date_time.cpp` example in `examples` folder.
195+
CRUD functions `get`, `get_no_throw`, `remove`, `update` (not `insert`) work only if your type has a primary key column. If you try to `get` an object that is mapped to your storage but has no primary key column a `std::system_error` will be thrown cause `sqlite_orm` cannot detect an id. If you want to know how to perform a storage without primary key take a look at `date_time.cpp` example in `examples` folder.
196196

197197
# Aggregate Functions
198198

examples/composite_key.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ int main() {
4242
"Drake",
4343
"Singer",
4444
});
45-
}catch(std::error_code e){
46-
cout << "exception = " << e.message() << endl;
45+
}catch(std::system_error e){
46+
cout << "exception = " << e.what() << endl;
4747
}
4848
storage.replace(User{
4949
2,

examples/foreign_key.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ int main(int argc, char **argv) {
6363
// does not correspond to row in the artist table.
6464
storage.replace(Track{ 14, "Mr. Bojangles", std::make_shared<int>(3) });
6565
assert(0);
66-
}catch(std::error_code e) {
67-
cout << e.message() << endl;
66+
}catch(std::system_error e) {
67+
cout << e.what() << endl;
6868
}
6969

7070
// This succeeds because a NULL is inserted into trackartist. A
@@ -77,8 +77,8 @@ int main(int argc, char **argv) {
7777
try{
7878
storage.update_all(set(assign(&Track::trackArtist, 3)), where(is_equal(&Track::trackName, "Mr. Bojangles")));
7979
assert(0);
80-
}catch(std::error_code e) {
81-
cout << e.message() << endl;
80+
}catch(std::system_error e) {
81+
cout << e.what() << endl;
8282
}
8383

8484
// Insert the required row into the artist table. It is then possible to
@@ -97,8 +97,8 @@ int main(int argc, char **argv) {
9797
// the track table contains a row that refer to it.
9898
storage.remove_all<Artist>(where(is_equal(&Artist::artistName, "Frank Sinatra")));
9999
assert(0);
100-
}catch(std::error_code e) {
101-
cout << e.message() << endl;
100+
}catch(std::system_error e) {
101+
cout << e.what() << endl;
102102
}
103103

104104
// Delete all the records from the track table that refer to the artist
@@ -111,8 +111,8 @@ int main(int argc, char **argv) {
111111
// exists records in the track table that refer to it.
112112
storage.update_all(set(assign(&Artist::artistId, 4)), where(is_equal(&Artist::artistName, "Dean Martin")));
113113
assert(0);
114-
}catch(std::error_code e) {
115-
cout << e.message() << endl;
114+
}catch(std::system_error e) {
115+
cout << e.what() << endl;
116116
}
117117

118118
// Once all the records that refer to a row in the artist table have

examples/index.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ int main(int argc, char **argv) {
4444
"Doe",
4545
"john.doe@sqlitetutorial.net",
4646
});
47-
}catch(std::error_code e){
48-
cout << e.message() << endl;
47+
}catch(std::system_error e){
48+
cout << e.what() << endl;
4949
}
5050
std::vector<Contract> moreContracts = {
5151
Contract{

examples/unique.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ int main(int argc, char **argv) {
3636
auto id1 = storage.insert(Entry{ 0, sameString, std::make_shared<std::string>("The way I are") });
3737
cout << "inserted " << storage.dump(storage.get<Entry>(id1)) << endl;
3838

39-
// it's ok but the next line will throw std::error_code
39+
// it's ok but the next line will throw std::system_error
4040

4141
auto id2 = storage.insert(Entry{ 0, sameString, std::make_shared<std::string>("I got you") });
4242
cout << "inserted " << storage.dump(storage.get<Entry>(id2)) << endl;
43-
} catch (std::error_code e) {
44-
cerr << e.message() << endl;
43+
} catch (std::system_error e) {
44+
cerr << e.what() << endl;
4545
}
4646

4747
return 0;

0 commit comments

Comments
 (0)