-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExceptions.h
More file actions
52 lines (46 loc) · 1.34 KB
/
Copy pathExceptions.h
File metadata and controls
52 lines (46 loc) · 1.34 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
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <string>
using namespace std;
// custom base class for all exceptions
class LogisticsException
{
protected:
string message;
public:
LogisticsException(string msg)
{
message = msg;
}
string getMessage() const
{
return message;
}
};
// thrown when a vehicle goes over its max weight capacity
class PayloadExceededException : public LogisticsException
{
public:
PayloadExceededException(string vName, double tryingToAdd, double maxLoad)
: LogisticsException("Error: " + vName + " cannot load " + to_string(tryingToAdd) + "kg. Max is " + to_string(maxLoad)) {}
};
// thrown if banned cargo is put on the wrong transport type
class CargoRestrictionException : public LogisticsException
{
public:
CargoRestrictionException(string vName, string reason)
: LogisticsException("Restriction on " + vName + ": " + reason) {}
};
// basic file opening/saving errors
class FileIOException : public LogisticsException
{
public:
FileIOException(string fName, string errorMsg)
: LogisticsException("File error with " + fName + " -> " + errorMsg) {}
};
// if an id doesn't match anything in the registry
class IDNotFoundException : public LogisticsException
{
public:
IDNotFoundException(string type, int id)
: LogisticsException(type + " ID " + to_string(id) + " not found.") {}
};