[ create a new paste ] login | about

Link: http://codepad.org/lgXsZcvg    [ raw code | output | fork ]

martin@mustbebuilt.co.uk - PHP, pasted on Sep 10:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
function checkNum($num) {
  if($num<10) {
    throw new Exception("Value must be more than 10");
  }
  return true;
}
try {
  checkNum(2);
  // if exception is not thrown 
  echo 'Exception not thrown';
}

//catch exception
catch(Exception $e) {
  echo 'Got You! Exception throw: ' .$e->getMessage();
}
?>


Output:
1
Got You! Exception throw: Value must be more than 10


Create a new paste based on this one


Comments: