异常问题 谢谢!!

package com.itheima.b_login;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sun.security.util.Password;

/**
 * Servlet implementation class UserServlet
 */
public class UserServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            String username = request.getParameter("username");
            String password = request.getParameter("password");

            User user = new User();
            user.setUsername(username);
            user.setUsername(password);

            UserService userService = new UserService();

            User existUser = userService.login(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        doGet(request, response);
    }

}

请问代码中的异常已经抛出了 为神恶魔还要try catch;它俩有什么不同,以及什么时候用, 什么时候一起用?

慕姐8946757
浏览 881回答 1
1回答

精慕门9254224

他声明的异常只是servlet 和io 异常,但你看他通过try catch 捕捉的是所有异常!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java