質問編集履歴

2

マークダウンと文言修正

2015/02/12 03:24

投稿

huang_2014
huang_2014

スコア34

test CHANGED
File without changes
test CHANGED
@@ -1,32 +1,73 @@
1
1
  PHPで Try/Catch ブロックが例外を Catch しませんでした。どうしたらいいのでしょうか?
2
2
 
3
- このページにある Example#1 を実行しようとしました。
4
- http://php.net/manual/ja/language.exceptions.php
5
3
 
6
4
 
5
+ このページにある Example#1 を実行しようとしました。
6
+
7
+ [http://php.net/manual/ja/language.exceptions.php](http://php.net/manual/ja/language.exceptions.php)
8
+
9
+
10
+
11
+
12
+
13
+ ```lang-<ここに言語を入力>
14
+
7
15
  function inverse($x) {
16
+
8
- if (!$x) {
17
+ if (!$x) {
18
+
9
- throw new Exception('ゼロによる除算。');
19
+ throw new Exception('ゼロによる除算。');
20
+
10
- }
21
+ }
22
+
11
- return 1/$x;
23
+ return 1/$x;
24
+
12
25
  }
13
26
 
27
+
28
+
14
29
  try {
30
+
15
- echo inverse(5) . "\n";
31
+ echo inverse(5) . "\n";
32
+
16
- echo inverse(0) . "\n";
33
+ echo inverse(0) . "\n";
34
+
17
- } catch (Exception $e) {
35
+ } catch (Exception $e) {
36
+
18
- echo '捕捉した例外: ', $e->getMessage(), "\n";
37
+ echo '捕捉した例外: ', $e->getMessage(), "\n";
38
+
19
39
  }
20
40
 
41
+
42
+
43
+
44
+
21
45
  // 実行は継続される
46
+
22
47
  echo "Hello World\n";
48
+
49
+ ```
50
+
51
+
52
+
23
53
 
24
54
 
25
55
  しかし、求めているアウトプットではなく、これが出ました。
56
+
57
+ ```lang-<ここに言語を入力>
58
+
26
59
  0.2
60
+
27
- Fatal error: Uncaught exception 'Exception' with message 'ゼロによる除算。'
61
+ Fatal error: Uncaught exception 'Exception' with message 'ゼロによる除算。'
62
+
63
+ ```
64
+
65
+
66
+
28
67
 
29
68
 
30
69
  使っている環境はPHP5.2.3 の UniServer3.5 です。
31
70
 
71
+
72
+
32
73
  宜しくお願いします。

1

2015/02/10 02:55

投稿

huang_2014
huang_2014

スコア34

test CHANGED
File without changes
test CHANGED
@@ -1,73 +1,32 @@
1
1
  PHPで Try/Catch ブロックが例外を Catch しませんでした。どうしたらいいのでしょうか?
2
2
 
3
+ このページにある Example#1 を実行しようとしました。
4
+ http://php.net/manual/ja/language.exceptions.php
3
5
 
4
6
 
5
- このページにある Example#1 を実行しようとしました。
6
-
7
- [http://php.net/manual/ja/language.exceptions.php](http://php.net/manual/ja/language.exceptions.php)
8
-
9
-
10
-
11
-
12
-
13
- ```lang-<ここに言語を入力>
14
-
15
7
  function inverse($x) {
16
-
17
- if (!$x) {
8
+ if (!$x) {
18
-
19
- throw new Exception('ゼロによる除算。');
9
+ throw new Exception('ゼロによる除算。');
20
-
21
- }
10
+ }
22
-
23
- return 1/$x;
11
+ return 1/$x;
24
-
25
12
  }
26
13
 
27
-
28
-
29
14
  try {
30
-
31
- echo inverse(5) . "\n";
15
+ echo inverse(5) . "\n";
32
-
33
- echo inverse(0) . "\n";
16
+ echo inverse(0) . "\n";
34
-
35
- } catch (Exception $e) {
17
+ } catch (Exception $e) {
36
-
37
- echo '捕捉した例外: ', $e->getMessage(), "\n";
18
+ echo '捕捉した例外: ', $e->getMessage(), "\n";
38
-
39
19
  }
40
20
 
41
-
42
-
43
-
44
-
45
21
  // 実行は継続される
46
-
47
22
  echo "Hello World\n";
48
-
49
- ```
50
-
51
-
52
-
53
23
 
54
24
 
55
25
  しかし、求めているアウトプットではなく、これが出ました。
56
-
57
- ```lang-<ここに言語を入力>
58
-
59
26
  0.2
60
-
61
- Fatal error: Uncaught exception 'Exception' with message 'ゼロによる除算。'
27
+ Fatal error: Uncaught exception 'Exception' with message 'ゼロによる除算。'
62
-
63
- ```
64
-
65
-
66
-
67
28
 
68
29
 
69
30
  使っている環境はPHP5.2.3 の UniServer3.5 です。
70
31
 
71
-
72
-
73
32
  宜しくお願いします。