-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.h
More file actions
42 lines (37 loc) · 1.18 KB
/
Copy pathexceptions.h
File metadata and controls
42 lines (37 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <exception>
#include <string>
using namespace std;
class StoreException : public exception {
protected:
string message;
public:
StoreException(const string& msg) : message(msg) {}
virtual const char* what() const throw() {
return message.c_str();
}
};
class InvalidPriceException : public StoreException {
public:
InvalidPriceException(double price)
: StoreException("Invalid price: " + to_string(price) +
". Price cannot be negative.") {}
};
class InvalidQuantityException : public StoreException {
public:
InvalidQuantityException(int qty)
: StoreException("Invalid quantity: " + to_string(qty) +
". Quantity cannot be negative.") {}
};
class OutOfStockException : public StoreException {
public:
OutOfStockException(int requested, int available)
: StoreException("Cannot buy " + to_string(requested) +
" only " + to_string(available) +
" items available.") {}
};
class FileException : public StoreException {
public:
FileException(const string& filename)
: StoreException("Failed to open file: " + filename) {}
};