forked from castello/spring_basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionController.java
More file actions
40 lines (33 loc) · 1.23 KB
/
Copy pathExceptionController.java
File metadata and controls
40 lines (33 loc) · 1.23 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
package com.fastcampus.ch2;
import java.io.FileNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
@Controller
public class ExceptionController {
@ExceptionHandler({NullPointerException.class, FileNotFoundException.class})
public String catcher2(Exception ex, Model m) {
m.addAttribute("ex", ex);
return "error";
}
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) // 200 -> 500
public String catcher(Exception ex, Model m) {
System.out.println("catcher() in ExceptionController");
System.out.println("m="+m);
// m.addAttribute("ex", ex);
return "error";
}
@RequestMapping("/ex")
public String main(Model m) throws Exception {
m.addAttribute("msg", "message from ExceptionController.main()");
throw new Exception("¿¹¿Ü°¡ ¹ß»ýÇß½À´Ï´Ù.");
}
@RequestMapping("/ex2")
public String main2() throws Exception {
throw new NullPointerException("¿¹¿Ü°¡ ¹ß»ýÇß½À´Ï´Ù.");
}
}