diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-09-09 11:51:37 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-09-09 11:51:37 (GMT) |
| commit | cd6c193e812f5fcef18e19d673b7a6740422d59c (patch) | |
| tree | 580de474105be52df66d7c0a290ab5f04a7e5c30 /src/virtualmachine/Exceptions.h | |
| parent | ba822dcbd2ac883a10ea128176b6613e3d5dc14f (diff) | |
| download | powder-cd6c193e812f5fcef18e19d673b7a6740422d59c.zip powder-cd6c193e812f5fcef18e19d673b7a6740422d59c.tar.gz | |
Virtual machine
Diffstat (limited to 'src/virtualmachine/Exceptions.h')
| -rw-r--r-- | src/virtualmachine/Exceptions.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/virtualmachine/Exceptions.h b/src/virtualmachine/Exceptions.h new file mode 100644 index 0000000..2dca461 --- /dev/null +++ b/src/virtualmachine/Exceptions.h @@ -0,0 +1,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() {}; + }; +}
\ No newline at end of file |
