Madchen Posted January 14, 2013 Share Posted January 14, 2013 I have couple question related to Exception class. Big question for me is when to use actually implementation of this class. 1. Do you use Exception for handling ALL errors? For example when user wants to login, do you give him error about wrong username and password (I think this is incorrect) or do you use for example another class which handles validation. For now i use Exception for errors in case database connection failed, when phpass fail to hash password..., basically something that developer can't handle. 3.. Where do you save errors? In txt file, in database? How you do that? Quote Link to comment https://forums.phpfreaks.com/topic/273134-exceptions-when-why-where/ Share on other sites More sharing options...
cpd Posted January 14, 2013 Share Posted January 14, 2013 Exceptions are generally used when something unexpected occurs. The to throw an exception you've defined yourself you must extend the Exception class, if it doesn't you'll get a fatal error. A typical exception you could throw is an InvalidArgumentException which could be used when a variable is of an incorrect type. Personally I've never used the Exception class on its own as I find it a little to broad and I certainly wouldn't use any exception class for all exceptions. Where you log errors is entirely up to you. People often used text files. You can write a logging class which could be dependency injected into any class that needs it. Quote Link to comment https://forums.phpfreaks.com/topic/273134-exceptions-when-why-where/#findComment-1405544 Share on other sites More sharing options...
Madchen Posted January 14, 2013 Author Share Posted January 14, 2013 Thx, I saw many people are using Exceptions form validation which is, imo, wrong. Quote Link to comment https://forums.phpfreaks.com/topic/273134-exceptions-when-why-where/#findComment-1405550 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.