回答編集履歴
2
修正
test
CHANGED
@@ -68,11 +68,9 @@
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
/*一般的なエラーを利用する*/
|
71
|
+
/*一般的なエラーを利用する(一部修正)*/
|
72
72
|
|
73
73
|
try{
|
74
|
-
|
75
|
-
if(!isset($_GET["name"])) trigger_error("",E_USER_NOTICE);
|
76
74
|
|
77
75
|
$x = $_GET["name"];
|
78
76
|
|
1
追記
test
CHANGED
@@ -11,3 +11,75 @@
|
|
11
11
|
```
|
12
12
|
|
13
13
|
などでチェックするものなのでわざわざ例外処理をするほどのことはないと思います
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
# 追記
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
念の為一般的なエラーの取得方法を追記しておきます
|
22
|
+
|
23
|
+
```PHP
|
24
|
+
|
25
|
+
set_error_handler('myErrorHandler');
|
26
|
+
|
27
|
+
function myErrorHandler($errno, $errstr, $errfile, $errline)
|
28
|
+
|
29
|
+
{
|
30
|
+
|
31
|
+
switch($errno) {
|
32
|
+
|
33
|
+
case E_NOTICE:
|
34
|
+
|
35
|
+
throw new exception("common notice:".$errstr."<br>");
|
36
|
+
|
37
|
+
break;
|
38
|
+
|
39
|
+
case E_USER_NOTICE:
|
40
|
+
|
41
|
+
throw new exception("my notice:".$errstr."<br>");
|
42
|
+
|
43
|
+
break;
|
44
|
+
|
45
|
+
default:
|
46
|
+
|
47
|
+
return false;
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
return true;
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
/*自分用のエラーを発生させる*/
|
58
|
+
|
59
|
+
try{
|
60
|
+
|
61
|
+
if(!isset($_GET["name"])) trigger_error("変数が未設定だよん",E_USER_NOTICE);
|
62
|
+
|
63
|
+
}catch(Exception $e){
|
64
|
+
|
65
|
+
print("エラー".$e->getMessage());
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
/*一般的なエラーを利用する*/
|
72
|
+
|
73
|
+
try{
|
74
|
+
|
75
|
+
if(!isset($_GET["name"])) trigger_error("",E_USER_NOTICE);
|
76
|
+
|
77
|
+
$x = $_GET["name"];
|
78
|
+
|
79
|
+
}catch(Exception $e){
|
80
|
+
|
81
|
+
print("エラー".$e->getMessage());
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
```
|