forked from The-Powder-Toy/The-Powder-Toy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Exceptions.h
69 lines (64 loc) · 1.41 KB
/
Exceptions.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <stdexcept>
#include <cstring>
#include "Format.h"
namespace vm
{
class RuntimeException: public std::exception
{
public:
RuntimeException() {}
const char * what() const throw()
{
return "VirtualMachine runtime exception";
}
~RuntimeException() throw() {};
};
class StackOverflowException: public RuntimeException
{
public:
StackOverflowException() {}
const char * what() const throw()
{
return "VirtualMachine Stack overflow";
}
~StackOverflowException() throw() {};
};
class StackUnderflowException: public RuntimeException
{
public:
StackUnderflowException() {}
const char * what() const throw()
{
return "VirtualMachine Stack underflow";
}
~StackUnderflowException() throw() {};
};
class AccessViolationException: public RuntimeException
{
int address;
char * _what;
public:
AccessViolationException(int address = 0) : address(address)
{
_what = strdup(std::string("VirtualMachine Access violation at "+format::NumberToString<int>(address)).c_str());
}
const char * what() const throw()
{
if(address)
return _what;
return "VirtualMachine Access violation";
}
~AccessViolationException() throw() {};
};
class OutOfMemoryException: public RuntimeException
{
public:
OutOfMemoryException() {}
const char * what() const throw()
{
return "VirtualMachine Out of memory";
}
~OutOfMemoryException() throw() {};
};
}