R
Raquel
I read this in a Java book about Declaring a method that throws
exceptions: "The Declaration itself doesn't do anything to actually
throw that exception should it occur; you have to do that yourself in
the body of the method".
In line with the above, I fail to understand the following piece of
code. It declares that it throws 'Exception' but then, does not
actually 'throw' it. I think I am missing some fundamental concept.
public static String format(String strData, int finalLen) throws
Exception
{
String finalStr;
if (finalLen <= strData.length())
{
finalStr = strData.substring(0, finalLen);
}
else
{
finalStr = strData;
for (int i = strData.length(); i < finalLen; i++)
{
finalStr = finalStr + " ";
}
}
return (finalStr);
} // format(String, int)
TIA
Raquel.
exceptions: "The Declaration itself doesn't do anything to actually
throw that exception should it occur; you have to do that yourself in
the body of the method".
In line with the above, I fail to understand the following piece of
code. It declares that it throws 'Exception' but then, does not
actually 'throw' it. I think I am missing some fundamental concept.
public static String format(String strData, int finalLen) throws
Exception
{
String finalStr;
if (finalLen <= strData.length())
{
finalStr = strData.substring(0, finalLen);
}
else
{
finalStr = strData;
for (int i = strData.length(); i < finalLen; i++)
{
finalStr = finalStr + " ";
}
}
return (finalStr);
} // format(String, int)
TIA
Raquel.