-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathDemoController.java
More file actions
54 lines (45 loc) · 1.8 KB
/
DemoController.java
File metadata and controls
54 lines (45 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.xys.exhandler.controller;
import com.xys.exhandler.exception.BaseException;
import com.xys.exhandler.exception.MyException1;
import com.xys.exhandler.exception.MyException2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
* @author xiongyongshun
* @version 1.0
* @created 16/8/29 13:04
*/
@RestController
public class DemoController {
private Logger logger = LoggerFactory.getLogger("GlobalExceptionHandler");
@RequestMapping("/ex1")
public Object throwBaseException() throws Exception {
throw new BaseException("This is BaseException.");
}
@RequestMapping("/ex2")
public Object throwMyException1() throws Exception {
throw new MyException1("This is MyException1.");
}
@RequestMapping("/ex3")
public Object throwMyException2() throws Exception {
throw new MyException2("This is MyException1.");
}
@RequestMapping("/ex4")
public Object throwIOException() throws Exception {
throw new IOException("This is IOException.");
}
@RequestMapping("/ex5")
public Object throwNullPointerException() throws Exception {
throw new NullPointerException("This is NullPointerException.");
}
@ExceptionHandler(NullPointerException.class)
public String controllerExceptionHandler(HttpServletRequest req, Exception e) {
logger.error("---ControllerException Handler---Host {} invokes url {} ERROR: {}", req.getRemoteHost(), req.getRequestURL(), e.getMessage());
return "---ControllerException Handler---:" + e.getMessage();
}
}