Welcome Guest, Not a member yet? Register   Sign In
catching exceptions
#1

[eluser]ericsodt[/eluser]
I come from a java background so working with PHP is a little different for me. I am trying to run some code in a try block and then if an exception is thrown throw it back to the view with the error message

Code:
try{
// this try WILL throw an error
             switch ($_POST['recurring']){
                case "day":
                    $dates = $this->dailyArray($_POST['startDate'],$_POST['endDate']);
                    break;
                case "week":
                    $dates = $this->weeklyArray($_POST['startDate'],$_POST['endDate']);
                    break;
                case "biweek":
                    $dates = $this->biweeklyArray($_POST['startDate'],$_POST['endDate']);
                    break;
                case "month":
                    $dates = $this->monthlyArray($_POST['startDate'],$_POST['endDate']);
                    break;
             }
        } catch (Exception $e) {
              echo "<br>".$e->getMessage()."<br>";
              $this->load->view('addEvent_view');
              exit();
        }

The view never gets loaded... can anyone help me out??
#2

[eluser]座頭市[/eluser]
If the try throws an error, I suppose the most obvious, initial question is: are you using PHP5? PHP4 doesn't support try...catch.
#3

[eluser]ericsodt[/eluser]
[quote author="座頭市" date="1190884069"]If the try throws an error, I suppose the most obvious, initial question is: are you using PHP5? PHP4 doesn't support try...catch.[/quote]

Yes, I am using PHP5. I have an echo statment in the catch and it is printing that on the page
#4

[eluser]座頭市[/eluser]
Try return; rather than exit;
#5

[eluser]ericsodt[/eluser]
THATS IT... Thanks!! I honestly would have never thought of that...




Theme © iAndrew 2016 - Forum software by © MyBB