Created
April 9, 2012 20:18
-
-
Save eliantor/2346353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
URL url=new URL("foo"); | |
} catch (MalformedURLException e) { | |
//throw new RuntimeException(e); | |
sneak(e); | |
} | |
StackTrace: | |
Exception in thread "main" java.net.MalformedURLException: no protocol: foo | |
at java.net.URL.<init>(URL.java:567) | |
at java.net.URL.<init>(URL.java:464) | |
at java.net.URL.<init>(URL.java:413) | |
at foo.Test.main(Test.java:15) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | |
at java.lang.reflect.Method.invoke(Method.java:597) | |
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) | |
invece di: | |
try { | |
URL url=new URL("foo"); | |
} catch (MalformedURLException e) { | |
throw new RuntimeException(e); | |
} | |
Exception in thread "main" java.lang.RuntimeException: java.net.MalformedURLException: no protocol: foo | |
at foo.Test.main(Test.java:17) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | |
at java.lang.reflect.Method.invoke(Method.java:597) | |
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) | |
Caused by: java.net.MalformedURLException: no protocol: foo | |
at java.net.URL.<init>(URL.java:567) | |
at java.net.URL.<init>(URL.java:464) | |
at java.net.URL.<init>(URL.java:413) | |
at foo.Test.main(Test.java:15) | |
... 5 more |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Util{ | |
/** | |
* lancia l'eccezione t anche se non è dichiarata nel metodo | |
* ma senza farne il wrapparla in una RuntimeException | |
*/ | |
public static RuntimeException throwUndeclared(Throwable t){ | |
if(t == null) throw new NullPointerException("t"); | |
Util.<RuntimeException>throw0(t); | |
return null; | |
} | |
private static <T extends Throwable> void throw0(Throwable t) throws T { | |
throw (T)t; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment