Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Abstract class not working

Hi Guys,

I have an abstract class which I use to display messages. i have a piece of code surrounded by a try / catch block but it seems the message is never passed to the Exception. When I put a hard coded message in the exception it works.

Can I anybody help me with this. Heres my code

// The Abstract Class

namespace App\Models;

asbstract class Messages
    const ERROR_MSG = "This is just an error message";
    const LOGIN_DENIED = "Login has been denied";

In my controller action I have this :

namespace App\Controllers;

use App\Messages;

class AuthController extends BaseController

    public function loginAction()
            $loggedIn = false;
            if (!$loggedIn) {
                throw new \Exception(Messages::LOGIN_DENIED);
        } catch(\Exception $e) {
            // The Message is never displayed
            echo $e->getMessage();

Please help. Thanks

Your messages class is using the namespace: App\Models, and you use: App\Messages (after setting an App\Controllers namespace)

Does throw new \Exception(\App\Models\Messages::LOGIN_DENIED); work?


No, the namespaces are correct. I reference the Messages class by using the "use" keyword.

edited Feb '15

I found the error, there was a duplicate const word in the class that just broke everything, the class has about 100 messages inside. Whats funny though Netbeans didnt pickup the issue and Phalcon did not issue a warning, error or notice.