How to throw exception without resetting stack trace?

With .NET Framework 4.5 there is now an ExceptionDispatchInfo which supports this exact scenario. It allows capturing a complete exception and rethrowing it from somewhere else without overwriting the contained stack trace. code sample due to request in comment using System.Runtime.ExceptionServices; class Test { private ExceptionDispatchInfo _exInfo; public void DeleteNoThrow(string path) { try { File.Delete(path); … Read more

Error handling with Mongoose

If you’re using Express, errors are typically handled either directly in your route or within an api built on top of mongoose, forwarding the error along to next. app.get(‘/tickets’, function (req, res, next) { PlaneTickets.find({}, function (err, tickets) { if (err) return next(err); // or if no tickets are found maybe if (0 === tickets.length) … Read more

Using Spring Boot’s ErrorController and Spring’s ResponseEntityExceptionHandler correctly

Spring Boot application has a default configuration for error handling – ErrorMvcAutoConfiguration. What it basically does, if no additional configuration provided: it creates default global error controller – BasicErrorController it creates default ‘error’ static view ‘Whitelabel Error Page’. BasicErrorController is wired to ‘/error’ by default. If there is no customized ‘error’ view in the application, … Read more

Is it possible to use custom error pages with MVC site but not Web API?

Well, after a nearly a year of letting this question marinade, I gave it another shot. Here’s the web.config magic that got me what I wanted: <!– inside of <configuration> to allow error responses from requests to /api through –> <location path=”api”> <system.webServer> <validation validateIntegratedModeConfiguration=”false” /> <httpErrors errorMode=”DetailedLocalOnly” existingResponse=”PassThrough” > <clear/> </httpErrors> </system.webServer> </location> <!– … Read more

Getting exception details in Python

You can use sys.exc_info to get information about the exception currently being handled, including the exception object itself. An IOError exception contains all of the information you need, including the filename, the errno, and a string describing the error: import sys try: f1 = open(‘example1’) f2 = open(‘example2’) except IOError: type, value, traceback = sys.exc_info() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)