exception: small example of how interfacing hs-java
authorBernhard Urban <lewurm@gmail.com>
Tue, 8 May 2012 19:06:27 +0000 (21:06 +0200)
committerBernhard Urban <lewurm@gmail.com>
Tue, 8 May 2012 19:06:27 +0000 (21:06 +0200)
Mate/BasicBlocks.hs
tests/Exception1.java [new file with mode: 0644]

index 07cc4f592c558fa9c821a2a77f26d611c3f70e79..1b03622c2369ebef3530529a9ea8c7d82a042613 100644 (file)
@@ -26,6 +26,9 @@ import JVM.Assembler
 import Mate.Utilities
 import Mate.Types
 
+#ifdef DEBUG
+import Text.Printf
+#endif
 
 -- for immediate representation to determine BBs
 type Offset = (Int, Maybe BBEnd) -- (offset in bytecode, offset to jump target)
@@ -89,6 +92,15 @@ parseMethod cls method = do
                      let msig = methodSignature $ (classMethods cls) !! 1
                      putStrLn $ toString (method `B.append` ": " `B.append` (encode msig))
                      printMapBB maybe_bb
+#endif
+#ifdef DEBUG
+                     -- small example how to get information about
+                     -- exceptions of a method
+                     -- TODO: remove ;-)
+                     let (Just m) = lookupMethod method cls
+                     case attrByName m "Code" of
+                      Nothing -> printf "exception: no handler for this method\n"
+                      Just exceptionstream -> printf "exception: \"%s\"\n" (show $ codeExceptions $ decodeMethod exceptionstream)
 #endif
                      return maybe_bb
 
diff --git a/tests/Exception1.java b/tests/Exception1.java
new file mode 100644 (file)
index 0000000..ed4ea90
--- /dev/null
@@ -0,0 +1,11 @@
+package tests;
+
+public class Exception1 {
+       public static void main(String []args) {
+               try {
+                       System.out.printf("hello exception stuff\n");
+               } catch (NullPointerException _) {
+                       System.out.printf("NullPointerException\n");
+               }
+       }
+}