public class ExceptionTest
{
private static final Logger log = Logger.getLogger(ExceptionTest.class);
public void login(String name, String password) throws MyException
{
if (!"fudan".equals(name) && !"wafd@1314".equals(password))
{
throw new MyException("user name or password error!","111");
}
}
public void writeMessage(String message, String filePath) throws MyException, FileNotFoundException
{
Writer writer = null;
log.debug("write message.....");
try {
writer = new FileWriter(new File(filePath));
writer.write(message);
}
catch (IOException e)
{
log.error("file not found!" + e);
throw new MyException(filePath + " is not exists", "22034", e);
// throw new FileNotFoundException();
}
finally
{
if (null != writer)
{
try
{
writer.close();
}
catch (IOException e)
{
log.error("close resource error" + e);
}
}
}
log.debug("notify message");
//同步
}
public static void main(String[] args) {
ExceptionTest test = new ExceptionTest();
try {
test.login("fudan", "wafd@1314");
test.writeMessage("werwer", "I:/werwer");
}
catch (MyException e)
{
System.out.println(e);
}
//jppewrtmgpf
catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
log4j属性文件
最新推荐文章于 2023-12-19 14:11:16 发布