classNumberRangeExceptionextendsException{publicNumberRangeException(Stringmsg){super(msg);}}publicclassTime{privateStringhour;privateStringminute;privateStringsecond;pri...
class NumberRangeException extends Exception
{
public NumberRangeException(String msg)
{
super(msg);
}
}
public class Time
{
private String hour;
private String minute;
private String second;
private static DecimalFormat twoDigits = new DecimalFormat( "00" );
public void setSecond( String s )throws NumberRangeException
{
try
{
if(Integer.parseInt(s)>100)
{
NumberRangeException e=new NumberRangeException("超范围了");
throw e;
}
second = s;
}
catch(NumberRangeException e)
{
System.out.println(e.toString());
}
}
}
部分代码省略,求大神支援!!!
展开