From: Bernhard Urban Date: Tue, 8 May 2012 19:06:27 +0000 (+0200) Subject: exception: small example of how interfacing hs-java X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mate.git;a=commitdiff_plain;h=16e69705ef729212262289fa9f185f171a5b8380 exception: small example of how interfacing hs-java --- diff --git a/Mate/BasicBlocks.hs b/Mate/BasicBlocks.hs index 07cc4f5..1b03622 100644 --- a/Mate/BasicBlocks.hs +++ b/Mate/BasicBlocks.hs @@ -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 index 0000000..ed4ea90 --- /dev/null +++ b/tests/Exception1.java @@ -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"); + } + } +}