一、服务端发布服务

package com.webservice;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService; @WebService
public interface IExceptionService { @WebResult(name = "addResult")
public int add(@WebParam(name = "x")
int x, @WebParam(name = "y")
int y) throws Exception; @WebResult(name = "subtractResult")
public int subtract(@WebParam(name = "x")
int x, @WebParam(name = "y")
int y) throws RuntimeException; @WebResult(name = "divideResult")
public int divide(@WebParam(name = "x")
int x, @WebParam(name = "y")
int y) throws DivideException;
}
package com.webservice;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date; import javax.jws.WebService; @WebService(endpointInterface = "com.webservice.IExceptionService")
public class ExceptionImpl implements IExceptionService { public int add(int x, int y) throws Exception {
if (x == 0 || y == 0) {
throw new Exception("add中Exception====X或者Y不能为0");
} else {
return x + y;
}
} public int subtract(int x, int y) throws RuntimeException {
if (x == 0 || y == 0) {
throw new RuntimeException("subtract中RunTimeException===X或者Y不能为0");
} else {
return x + y;
}
} public int divide(int x, int y) throws DivideException {
if (x == 0 || y == 0) {
throw new DivideException("divide中DivideException===X或者Y不能为0");
} else {
return x + y;
}
} }
  •   自定义异常
package com.webservice;

public class DivideException extends Exception {

    public DivideException() {
super();
} public DivideException(String arg0, Throwable arg1, boolean arg2,
boolean arg3) {
super(arg0, arg1, arg2, arg3);
} public DivideException(String arg0, Throwable arg1) {
super(arg0, arg1);
} public DivideException(String arg0) {
super(arg0);
} public DivideException(Throwable arg0) {
super(arg0);
} }
package com.publish;

import javax.xml.ws.Endpoint;

import com.webservice.BeanImpl;
import com.webservice.DateImpl;
import com.webservice.ExceptionImpl;
import com.webservice.ListImpl;
import com.webservice.MapImpl;
import com.webservice.StrImpl; public class TestPublish {
public static void main(String[] args) { Endpoint.publish("http://localhost:9090/ExceptionService",
new ExceptionImpl());
System.out.println("发布成功...");
}
}

二、客户端

package com.exception;

public class TestMain {
public static void main(String[] args) {
//TestMain.add(); // TestMain.subtract(); TestMain.divide();
} private static void add() {
// 服务端没有异常
// 客户端:com.exception.Exception_Exception
IExceptionService exceptionService = new ExceptionImplService()
.getExceptionImplPort(); try {
exceptionService.add(1, 0);
} catch (Exception_Exception e) {
Exception exception = e.getFaultInfo(); String server_msg = exception.getMessage(); System.out.println(server_msg); e.printStackTrace(); } } private static void subtract() {
// 服务端的异常:java.lang.RuntimeException
// 客户端的异常:javax.xml.ws.soap.SOAPFaultException
IExceptionService exceptionService = new ExceptionImplService()
.getExceptionImplPort(); exceptionService.subtract(3, 0);
} private static void divide() {
IExceptionService exceptionService = new ExceptionImplService()
.getExceptionImplPort(); try {
exceptionService.divide(1, 0);
} catch (DivideException_Exception e) {
System.out.println(e.getFaultInfo().getMessage());
e.printStackTrace();
} } }

(五)web服务中的异常处理的更多相关文章

  1. ASP.NET Web API 中的异常处理(转载)

    转载地址:ASP.NET Web API 中的异常处理

  2. 【ASP.NET Web API教程】4.3 ASP.NET Web API中的异常处理

    原文:[ASP.NET Web API教程]4.3 ASP.NET Web API中的异常处理 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本系列教程,请先看前面的内 ...

  3. web应用中的异常处理

    楼主前几天写了一篇“Java子线程中的异常处理(通用)”文章,介绍了在多线程环境下3种通用的异常处理方法. 但是平时大家的工作一般是基于开发框架进行的(比如Spring MVC,或Spring Boo ...

  4. Web服务中延时对QoE(体验质量)的影响

    S. Egger等人在论文<WAITING TIMES IN QUALITY OF EXPERIENCE FOR WEB BASED SERVICES>中,研究了Web服务中延时对主观感受 ...

  5. 2017.10.28 针对Java Web应用中错误异常处理方法的运用

    针对Java Web应用中错误异常处理方法的运用 在javaweb中其异常都需要对Checked Exception之下的Exception进行继承,并且有选择地对发生的错误和异常进行处理.Java同 ...

  6. REST服务中的异常处理

    在REST服务中,服务端如果产生了异常信息,无论是业务异常或是系统异常,如果直接将异常抛出,在客户端浏览器中,是无法获取异常的详细,只能获取一个StateCode 500 Internal Serve ...

  7. 第五章 python中的异常处理

    每种编程语言都会有自己的异常处理机制,虽然各有特色,但基本上都差不多,那么python中强大异常处理机制是什么样的呢? 一.异常: python用异常对象来表示异常情况,遇到错误后,会引发异常.如果异 ...

  8. 【Web】Web开发中的异常处理方案

    我认为最合理的做法: 1.dao层不捕获异常.不抛出异常:spring框架将底层的数据库checked异常封装成unchecked异常了 2.service层捕获异常,并抛出自定义unchecked异 ...

  9. 在 ASP.NET Core Web API中使用 Polly 构建弹性容错的微服务

    在 ASP.NET Core Web API中使用 Polly 构建弹性容错的微服务 https://procodeguide.com/programming/polly-in-aspnet-core ...

随机推荐

  1. Keil综合(03)_map文件全解析[转]

    推荐分享一个大神的人工智能教程.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到人工智能的队伍中来!http://www.captainbed.net/strongerhuang 我的网站:ht ...

  2. python 设计模式之中介者模式

    #先啰嗦一下 至少半个多月的样子没写博客了,月初去了趟黄山,赏了美景,自然没时间也没条件敲博客了,一个多星期就这么过去了.返回深圳后,工作积压了一堆,然后白天就马不停蹄的忙工作,晚上回家伺候小娃,又想 ...

  3. 使用oid2name列出数据库和对应的oid

    [postgres@postgre base]$ ll total 172 drwx------ 2 postgres postgres 12288 Dec 6 09:21 1 drwx------ ...

  4. 如何git revert merge commit?

    答: git revert -m <parent-number> <commit-id> (适用于merge操作的commit) 参考资料: https://blog.csdn ...

  5. mybatis bind exception

    springboot  项目  搜了半天 网上的解决方法千篇一律,最终问题 原因 ,yml 文件路径问题 mybatis: mapper-locations: classpath:com/yang/f ...

  6. iOS-AppDelegate详解

    项目中AppDelegate详解 1.AppDelegate.h //模板默认引入程序需要使用“类”的框架,即UIKit.h头文件,使它包含在程序中 #import <UIKit/UIKit.h ...

  7. iOS-UINavigationController多控制器管理

    UINavigationController 7.8.1 添加子控制器进栈 UINavigationController *nav = [[UINavigationController alloc]  ...

  8. python:解析requests返回的response(json格式)

    import requests, json r = requests.get('http://192.168.207.160:9000/api/qualitygates/project_status? ...

  9. 2.app自动化测试--adb常用API

    adb常用API  Driver.current_activity 获取当前运行应用界面的启动名 Driver.current_package 获取当前运行应用的包名 Driver.contexts ...

  10. Python异常 --Python

    一.常见的异常类型 FileNotFoundError:找不到指定文件的异常 NameError:未声明或者未初始化对象 BaseException:所有异常的基类 二.异常处理语句 1.try... ...