pertama kita membuat library dengan nama cek_error.php
dan mengisikan script dalam file tersebut seperti dibawah ini :
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class cek_error
{
public function __construct()
{
$this->CI =& get_instance();
ini_set('display_errors','on');
error_reporting(E_ALL^E_NOTICE);
}
function inverse($x,$y){
if($y==0){
throw new Exception('0');
}else{
return ($x/$y)*100;
}
}
}
setelah membuat library selanjutnya load library yang telah dibuat dicontroller dan menggunakan try and catch :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class latihan extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library(array('cek_error'));
ini_set('display_errors','on');
error_reporting(E_ALL^E_NOTICE);
}
function index(){
try{
$tfi = $this->cek_error->inverse(10,0);
}catch(Exception $e){
$tfi = $e->getMessage();
}
echo round($tfi,2);
}
}
Jika ingin menapilkan try and catch di view tinggal memindahkan saja try and catch tersebut diview.
Slots Machines for Free: Best Games for Mobile Devices
ReplyDeleteSlots Machines. Slot machine for 슬롯커뮤니티 mobile. 바카라 검증사이트 Play free Slots Machines games online 강원 랜드 떡 in our directory. No download required. 1xbet 후기 Have fun with your favorite slots machine 1xbet