C
Carl Howells
This is such a bad idea. And yet, it works:
--- code ----
public class Test
{
private int b;
public Test(int a) throws Test.HoldingException
{
b = a;
throw new HoldingException(this);
}
public static void main(String [] args)
{
try
{
Test s = new Test(10);
}
catch (Test.HoldingException e)
{
Test s = (Test)e.getHeld();
System.out.println(s.toString() + " " + s.b);
}
}
private static class HoldingException extends Exception
{
Object held;
public HoldingException(Object o)
{
held = o;
}
public Object getHeld()
{
return held;
}
}
}
--- code ----
I'm kind of sad that this works. At least everyone who sees it should
know it's a bad idea.
--- code ----
public class Test
{
private int b;
public Test(int a) throws Test.HoldingException
{
b = a;
throw new HoldingException(this);
}
public static void main(String [] args)
{
try
{
Test s = new Test(10);
}
catch (Test.HoldingException e)
{
Test s = (Test)e.getHeld();
System.out.println(s.toString() + " " + s.b);
}
}
private static class HoldingException extends Exception
{
Object held;
public HoldingException(Object o)
{
held = o;
}
public Object getHeld()
{
return held;
}
}
}
--- code ----
I'm kind of sad that this works. At least everyone who sees it should
know it's a bad idea.