Java 在基于soap的web服务中异常抛出cutom消息

Java 在基于soap的web服务中异常抛出cutom消息,java,soap,Java,Soap,我正在使用web服务从数据库中获取一些用户详细信息。我不知道如何抛出和处理异常 @WebMethod(operationName ="My operataion") @WebResult(name="Some Type") public UserDetails getUserInfo(@WebParam(name="mailID")int mailID) throws SQLException{ UserDetails user= new UserDetails(

我正在使用web服务从数据库中获取一些用户详细信息。我不知道如何抛出和处理异常

@WebMethod(operationName ="My operataion")
    @WebResult(name="Some Type")
    public UserDetails getUserInfo(@WebParam(name="mailID")int mailID) throws SQLException{
        UserDetails user= new UserDetails();
        User umanager= new User();
        user= umanager.getUserInfo(custID);
        return user;


    }
我想在客户端捕获异常,并修改错误消息,如
“无法连接到数据库”

任何人都可以告诉如何做,并发送自定义异常


提前感谢。

看一下以下教程:

  • 对于你的函数,你可以这样写

    public UserDetails getUserInfo(@WebParam(name="mailID")int mailID) throws SQLException{
        // if your connection not established then   
        throw new SQLException("Unable to connect to Database");
    }