I have the following code
`
package com.test.Custom;
public class StreamError
{
public static void main(String[] args)
{
try
{
String str = "Hello";
if (!str.equals("Hello"))
{
throw new RuntimeException("None of the Directories Exists-Message failed");
}
int inf = ster(9);
System.out.print(inf);
}
catch (RuntimeException stex)
{
//getTrace().addWarning("Failing the message");
RuntimeException rme = new RuntimeException("None of the Directories Exists-Message failed", stex);
throw rme;
}
}
public static int ster(int intg)
{ try
{
if (intg >6)
{
throw new RuntimeException("None of the files Exists-Message failed");
}
else
return intg;
}
catch (RuntimeException ste)
{
//getTrace().addWarning("Failing the message");
RuntimeException pme = new RuntimeException("None of the files Exists-Message failed", ste);
throw pme;
}
}
}
`
When I execute this for integer >6, e.g 9 I can see it throws Runtime exceptions from both the catch blocks- even though the Directory part is correct , i.e String str = Hello.
Exception in thread "main" java.lang.RuntimeException: None of the Directories Exists-Message failed
at com.test.Custom.StreamError.main(StreamError.java:21)
Caused by: java.lang.RuntimeException: None of the files Exists-Message failed
at com.test.Custom.StreamError.ster(StreamError.java:39)
at com.test.Custom.StreamError.main(StreamError.java:11)
Caused by: java.lang.RuntimeException: None of the files Exists-Message failed
at com.test.Custom.StreamError.ster(StreamError.java:31)
... 1 more
But, when I run this for wrong directory(say abcd) and correct integer (say 2) it returns only the runtime exception from directory catch block.
Exception in thread "main" java.lang.RuntimeException: None of the Directories Exists-Message failed
at com.test.Custom.StreamError.main(StreamError.java:22)
Caused by: java.lang.RuntimeException: None of the Directories Exists-Message failed
at com.test.Custom.StreamError.main(StreamError.java:13
) am I missing something very basic? Please help.
Thanks Sugata