[Spring Boot2.4.2] 例外処理

TestException.java

package com.example.demo;

public class TestException extends RuntimeException {
	private static final long serialVersionUID = 1L;
	
	TestException(String msg){
		super(msg);
	}
}

index.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="utf-8" />
    <title>Check</title>
  </head>
  <body>
    <p th:text="${message1}"></p>
  </body>
</html>

MainController.java

package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/test1")
public class MainController {

    @GetMapping
	public String index(Model model)  {
	runSample();
	 return "test1/index";
	}
    
    void runSample()   {
		int i = 5;
		if (i == 5) {
			throw new TestException("独自の例外です"); 
		}
	}
}

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Feb 07 16:57:28 JST 2021
There was an unexpected error (type=Internal Server Error, status=500).
独自の例外です
com.example.demo.TestException: 独自の例外です