Application_Error in global.asax not catching errors in WebAPI

Abstract out your error handling logic from Application_Error into its own function. Create a Web API exception filter. //register your filter with Web API pipeline //this belongs in the Application_Start event in Global Application Handler class (global.asax) //or some other location that runs on startup GlobalConfiguration.Configuration.Filters.Add(new LogExceptionFilterAttribute()); //Create filter public class LogExceptionFilterAttribute : ExceptionFilterAttribute { … Read more

Error logging in C#

Lots of log4net advocates here so I’m sure this will be ignored, but I’ll add my own preference: System.Diagnostics.Trace This includes listeners that listen for your Trace() methods, and then write to a log file/output window/event log, ones in the framework that are included are DefaultTraceListener, TextWriterTraceListener and the EventLogTraceListener. It allows you to specify … Read more

How to avoid isset() and empty()

For those interested, I have expanded this topic into a small article, which provides the below information in a somewhat better structured form: The Definitive Guide To PHP’s isset And empty IMHO you should think about not just making the app “E_NOTICE compatible”, but restructuring the whole thing. Having hundreds of points in your code … Read more

Why is exception handling bad? [closed]

Exceptions make it really easy to write code where an exception being thrown will break invariants and leave objects in an inconsistent state. They essentially force you to remember that most every statement you make can potentially throw, and handle that correctly. Doing so can be tricky and counter-intuitive. Consider something like this as a … Read more

What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such

TL;DR Always have mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); in your mysqli connection code and always check the PHP errors. Always replace every PHP variable in the SQL query with a question mark, and execute the query using prepared statement. It will help to avoid syntax errors of all sorts. Explanation Sometimes your MySQLi code produces an error … Read more

tech