summaryrefslogtreecommitdiff
path: root/src/virtualmachine/Exceptions.h
blob: fbc4341766cc0c7e26770ed909ebcc321d827e87 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include <stdexcept>
#include <cstring>
#include "Format.h"

namespace vm
{
	class RuntimeException: public std::exception
	{
		char * error;
	public:
		RuntimeException() : error(NULL) {}
		RuntimeException(char * message) : error(strdup(message)) {}
		const char * what() const throw()
		{
			if(error)
				return error;
			else
				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 JITException: public RuntimeException
	{
		char * _what;
	public:
		JITException(const char * what2)
		{
			_what = strdup(what2);
		}
		const char * what() const throw()
		{
			return _what;
		}
		~JITException() throw() {};
	};

	class OutOfMemoryException: public RuntimeException
	{
	public:
		OutOfMemoryException() {}
		const char * what() const throw()
		{
			return "VirtualMachine Out of memory";
		}
		~OutOfMemoryException() throw() {};
	};
}