tzezula@287: /** tzezula@287: * Back 2 Browser Bytecode Translator tzezula@287: * Copyright (C) 2012 Jaroslav Tulach tzezula@287: * tzezula@287: * This program is free software: you can redistribute it and/or modify tzezula@287: * it under the terms of the GNU General Public License as published by tzezula@287: * the Free Software Foundation, version 2 of the License. tzezula@287: * tzezula@287: * This program is distributed in the hope that it will be useful, tzezula@287: * but WITHOUT ANY WARRANTY; without even the implied warranty of tzezula@287: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tzezula@287: * GNU General Public License for more details. tzezula@287: * tzezula@287: * You should have received a copy of the GNU General Public License tzezula@287: * along with this program. Look for COPYING file in the top folder. tzezula@287: * If not, see http://opensource.org/licenses/GPL-2.0. tzezula@285: */ tzezula@285: package org.apidesign.vm4brwsr; tzezula@285: jaroslav@423: import org.apidesign.bck2brwsr.core.JavaScriptBody; jaroslav@423: tzezula@285: /** tzezula@285: * tzezula@285: * @author tom tzezula@285: */ tzezula@285: public class Exceptions { jaroslav@400: private Exceptions() { jaroslav@400: } tzezula@285: tzezula@285: public static int methodWithTryCatchNoThrow() { tzezula@285: int res = 0; tzezula@285: try { tzezula@285: res = 1; tzezula@285: } catch (IllegalArgumentException e) { tzezula@285: res = 2; tzezula@285: } tzezula@285: //join point tzezula@285: return res; tzezula@285: } tzezula@285: tzezula@285: public static int methodWithTryCatchThrow() { tzezula@285: int res = 0; tzezula@285: try { tzezula@285: res = 1; tzezula@285: throw new IllegalArgumentException(); tzezula@285: } catch (IllegalArgumentException e) { tzezula@285: res = 2; tzezula@285: } tzezula@285: //join point tzezula@285: return res; tzezula@285: } jaroslav@423: jaroslav@423: @JavaScriptBody(args = "msg", body = "throw msg;") jaroslav@423: public static void thrw(String msg) {} jaroslav@423: jaroslav@423: public static String catchThrowableCatchesAll() { jaroslav@423: try { jaroslav@423: thrw("Hello!"); jaroslav@423: return "Not here!"; jaroslav@423: } catch (Throwable ex) { jaroslav@423: return ex.getMessage(); jaroslav@423: } jaroslav@423: } tzezula@285: jaroslav@400: public static String newInstance(String n) { jaroslav@400: try { jaroslav@400: Class c; jaroslav@400: try { jaroslav@400: c = Class.forName(n); jaroslav@400: } catch (ClassNotFoundException ex) { jaroslav@400: return ("CNFE:" + ex.getMessage()).toString(); jaroslav@400: } jaroslav@400: return c.newInstance().getClass().getName(); jaroslav@400: } catch (InstantiationException | IllegalAccessException ex) { jaroslav@400: return ex.getMessage(); jaroslav@400: } jaroslav@400: } jaroslav@401: jaroslav@401: private static int counter; jaroslav@401: public static int readCounter(String n) throws ClassNotFoundException { jaroslav@401: try { jaroslav@401: Class.forName(n); jaroslav@401: } finally { jaroslav@401: counter++; jaroslav@401: } jaroslav@401: return counter; jaroslav@401: } tzezula@285: }