Better error handling.
[hs-java.git] / JVM / Exceptions.hs
index b90db45a9d35b4c4d052a89f84e71b868c772a2e..2d47af445f0b87ebf502451a7ce60f0f480d37ef 100644 (file)
@@ -2,6 +2,9 @@
 module JVM.Exceptions where
 
 import Control.Monad.Exception
+import qualified Data.ByteString.Lazy as B
+
+import JVM.ClassFile
 
 data NoItemInPool = forall a. Show a => NoItemInPool a
   deriving (Typeable)
@@ -11,6 +14,36 @@ instance Exception NoItemInPool
 instance Show NoItemInPool where
   show (NoItemInPool s) = "Internal error: no such item in pool: <" ++ show s ++ ">"
 
+data UnexpectedEndMethod = UnexpectedEndMethod
+  deriving (Typeable)
+
+instance Show UnexpectedEndMethod where
+  show UnexpectedEndMethod = "endMethod without startMethod!"
+
+instance Exception UnexpectedEndMethod
+
+data ENotLoaded = ClassFileNotLoaded FilePath
+                | JARNotLoaded FilePath String
+  deriving (Typeable)
+
+instance Show ENotLoaded where
+  show (ClassFileNotLoaded p) = "Class file was not loaded: " ++ p
+  show (JARNotLoaded p c) = "Class was not loaded from JAR: " ++ p ++ ": " ++ c
+
+instance Exception ENotLoaded
+
+data ENotFound = ClassNotFound String
+               | FieldNotFound String B.ByteString
+               | MethodNotFound String B.ByteString
+  deriving (Typeable)
+
+instance Show ENotFound where
+  show (ClassNotFound p) = "No such class in ClassPath: " ++ p
+  show (FieldNotFound c f) = "No such field in class " ++ c ++ ": " ++ toString f
+  show (MethodNotFound c m) = "No such method in class " ++ c ++ ": " ++ toString m
+
+instance Exception ENotFound
+
 force :: String -> EM AnyException a -> a
 force s x =
   case tryEM x of