Skip to content

Implement exception handling #2

@DevOnWheels

Description

@DevOnWheels

Have a look at \controllers\dashboard.php :)

You're checking your input for validity by calling a function checkInputString(). Per intention your function SHOULD return just true or false (valid/ not valid), instead you're returning a string or null. A better way would be:

function isValidInput($input, ... ) {
    if ($input_fails_your_condition) {
        throw new Form_Validation_Exception('Something went horribly wrong!');
    }
    
    return true;
}

In your controller, you then just call your function within a try { ... } catch(Form_Validation_Exception $e) { ... }.

What's to learn here:

  • be precise in your function declarations
  • check for the correct return values (Duck-Typing is a bitch ;) )
  • error/ exception handling should be concentrated at certain points (like your controller)

Happy coding! :)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions