author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Mon, 31 Dec 2012 17:50:27 +0100 | |
changeset 401 | a9be982d9b9c |
parent 400 | 5452b9fbd253 |
child 423 | 9b5868bf56ec |
permissions | -rw-r--r-- |
tzezula@287 | 1 |
/** |
tzezula@287 | 2 |
* Back 2 Browser Bytecode Translator |
tzezula@287 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
tzezula@287 | 4 |
* |
tzezula@287 | 5 |
* This program is free software: you can redistribute it and/or modify |
tzezula@287 | 6 |
* it under the terms of the GNU General Public License as published by |
tzezula@287 | 7 |
* the Free Software Foundation, version 2 of the License. |
tzezula@287 | 8 |
* |
tzezula@287 | 9 |
* This program is distributed in the hope that it will be useful, |
tzezula@287 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
tzezula@287 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
tzezula@287 | 12 |
* GNU General Public License for more details. |
tzezula@287 | 13 |
* |
tzezula@287 | 14 |
* You should have received a copy of the GNU General Public License |
tzezula@287 | 15 |
* along with this program. Look for COPYING file in the top folder. |
tzezula@287 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
tzezula@285 | 17 |
*/ |
tzezula@285 | 18 |
package org.apidesign.vm4brwsr; |
tzezula@285 | 19 |
|
tzezula@285 | 20 |
/** |
tzezula@285 | 21 |
* |
tzezula@285 | 22 |
* @author tom |
tzezula@285 | 23 |
*/ |
tzezula@285 | 24 |
public class Exceptions { |
jaroslav@400 | 25 |
private Exceptions() { |
jaroslav@400 | 26 |
} |
tzezula@285 | 27 |
|
tzezula@285 | 28 |
public static int methodWithTryCatchNoThrow() { |
tzezula@285 | 29 |
int res = 0; |
tzezula@285 | 30 |
try { |
tzezula@285 | 31 |
res = 1; |
tzezula@285 | 32 |
} catch (IllegalArgumentException e) { |
tzezula@285 | 33 |
res = 2; |
tzezula@285 | 34 |
} |
tzezula@285 | 35 |
//join point |
tzezula@285 | 36 |
return res; |
tzezula@285 | 37 |
} |
tzezula@285 | 38 |
|
tzezula@285 | 39 |
public static int methodWithTryCatchThrow() { |
tzezula@285 | 40 |
int res = 0; |
tzezula@285 | 41 |
try { |
tzezula@285 | 42 |
res = 1; |
tzezula@285 | 43 |
throw new IllegalArgumentException(); |
tzezula@285 | 44 |
} catch (IllegalArgumentException e) { |
tzezula@285 | 45 |
res = 2; |
tzezula@285 | 46 |
} |
tzezula@285 | 47 |
//join point |
tzezula@285 | 48 |
return res; |
tzezula@285 | 49 |
} |
tzezula@285 | 50 |
|
jaroslav@400 | 51 |
public static String newInstance(String n) { |
jaroslav@400 | 52 |
try { |
jaroslav@400 | 53 |
Class c; |
jaroslav@400 | 54 |
try { |
jaroslav@400 | 55 |
c = Class.forName(n); |
jaroslav@400 | 56 |
} catch (ClassNotFoundException ex) { |
jaroslav@400 | 57 |
return ("CNFE:" + ex.getMessage()).toString(); |
jaroslav@400 | 58 |
} |
jaroslav@400 | 59 |
return c.newInstance().getClass().getName(); |
jaroslav@400 | 60 |
} catch (InstantiationException | IllegalAccessException ex) { |
jaroslav@400 | 61 |
return ex.getMessage(); |
jaroslav@400 | 62 |
} |
jaroslav@400 | 63 |
} |
jaroslav@401 | 64 |
|
jaroslav@401 | 65 |
private static int counter; |
jaroslav@401 | 66 |
public static int readCounter(String n) throws ClassNotFoundException { |
jaroslav@401 | 67 |
try { |
jaroslav@401 | 68 |
Class.forName(n); |
jaroslav@401 | 69 |
} finally { |
jaroslav@401 | 70 |
counter++; |
jaroslav@401 | 71 |
} |
jaroslav@401 | 72 |
return counter; |
jaroslav@401 | 73 |
} |
tzezula@285 | 74 |
} |