Raquel <> scribbled the following:
> 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.
It calls a lot of other methods, any of which can throw an exception.
If such a thing happens, then this method also throws the same
exception.
> 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)
--
/-- Joona Palaste () ------------- Finland --------\
\--
http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Life without ostriches is like coffee with milk."
- Mika P. Nieminen