一、服务端发布服务

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. Fences_3.08破解安装

    Fences_3.08破解安装 一.总结 一句话总结: 找破解软件去吾爱破解论坛,非常节约时间 二.Fences_3.08破解安装(亲测有效) 来源:吾爱破解论坛 百度网盘下载地址:链接:https: ...

  2. leetcode 62. Unique Paths 、63. Unique Paths II

    62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...

  3. 005-多线程-集合-Map-ConcurrentSkipListMap

    一.概述 ConcurrentSkipListMap是线程安全的有序的哈希表,适用于高并发的场景. ConcurrentSkipListMap和TreeMap,它们虽然都是有序的哈希表.但是,第一,它 ...

  4. osg qt ifc

    ui_ifcproject_20190702.h #pragma once /************************************************************* ...

  5. 123456---com.twoapp.ErTongNongChangPinTu---儿童农场拼图

    com.twoapp.ErTongNongChangPinTu---儿童农场拼图

  6. using kafkacat reset kafka offset

    1. install kafkacat Ubuntu apt-get install kafkacat CentOS install deepenency yum install librdkafka ...

  7. pytorch0.4.1安装

    pytorch官网:https://pytorch.org/ 这里安装pytorch0.4.1版本(最新版本为1.3.0系列,但是在跑github上的一些项目时会不断地报“ UseWarinig:Le ...

  8. FastCGI模式下安装Xcache

    PHP执行的时候,会被编译成opcode,然后 zend引擎会执行opcode.也就是说,如果你两次执行同一个php程序,每次执行,他都要把php代码编译成opcodexcache的意义在于,当你第一 ...

  9. hadoop在windows上的配置文件

    core-site.xml <configuration> <property> <name>hadoop.tmp.dir</name> <val ...

  10. END使用

    [root@bogon ~]# cat d.sh #!/bin/bash#. /etc/init.d/functionscat <<END+------------------------ ...