Skip to content

Instantly share code, notes, and snippets.

@frankkienl
Created June 3, 2015 07:25
Show Gist options
  • Save frankkienl/06f4ba0da8e38e553258 to your computer and use it in GitHub Desktop.
Save frankkienl/06f4ba0da8e38e553258 to your computer and use it in GitHub Desktop.
Java Exceptions Testing. Finding out how re-throwing affects the stacktrace.
//Java Exceptions Testing. Finding out how re-throwing affects the stacktrace.
//Tested in: http://www.compilejava.net/
public class HelloWorld
{
public static void main(String[] args) throws Exception
{
testThrowUp();
}
public static void testThrowUp(){
testThrowUp1();
}
public static void testThrowUp1(){
testThrowUp2();
}
public static void testThrowUp2(){
testThrowUp3();
}
public static void testThrowUp3(){
testThrowUp4();
}
public static void testThrowUp4(){
throw new RuntimeException("Some Message");
}
}
/////////////////////////////////////////////////////
public class HelloWorld
{
public static void main(String[] args) throws Exception
{
testThrowUp();
}
public static void testThrowUp(){
try {testThrowUp1();} catch (Exception up){
throw up;
}
}
public static void testThrowUp1(){
try {testThrowUp2();} catch (Exception up){
throw up;
}
}
public static void testThrowUp2(){
try {testThrowUp3(); } catch (Exception up){
throw up;
}
}
public static void testThrowUp3(){
try {
testThrowUp4();
} catch (Exception up){
throw up;
}
}
public static void testThrowUp4(){
throw new RuntimeException("Some Message");
}
}
///////////////////////////////////
public class HelloWorld
{
public static void main(String[] args) throws Exception
{
testThrowUp();
}
public static void testThrowUp(){
try {testThrowUp1();} catch (Exception up){
throw up;
}
}
public static void testThrowUp1(){
try {testThrowUp2();} catch (Exception up){
throw up;
}
}
public static void testThrowUp2(){
try {testThrowUp3(); } catch (Exception up){
throw up;
}
}
public static void testThrowUp3() {
try {
testThrowUp4();
} catch (Exception up){
throw new RuntimeException(up);
}
}
public static void testThrowUp4(){
throw new RuntimeException("Some Message");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment