exception-handling

Catching a generic exception

我怕爱的太早我们不能终老 提交于 2019-12-10 15:26:47
问题 Problem I am writing a Result type in Java, and I have found a need for it to have a method that performs an operation which may fail, and then encapulates the value or exception in a new Result object. I had hoped this would work: @FunctionalInterface public interface ThrowingSupplier<R, E extends Throwable> { R get() throws E; } public class Result<E extends Throwable, V> { ... public static <E extends Throwable, V> Result<E, V> of(ThrowingSupplier<V, E> v) { try { return value(v.get()); }

Pros and Cons of implementing a generic custom exception

帅比萌擦擦* 提交于 2019-12-10 15:25:24
问题 What are the pros and cons of implementing a custom exception as follows: Create an enum which represents error messages in its descriptions: public class Enums { public enum Errors { [Description("This is a test exception")] TestError, ... } } Create a custom exception class: public class CustomException : ApplicationException { protected Enums.Errors _customError; public CustomException(Enums.Errors customError) { this._customError = customError; } public override string Message { get {

Nested Exception handling in Spring MVC

浪子不回头ぞ 提交于 2019-12-10 15:23:43
问题 I am getting the following error: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException And to handle this in a controller, I have used the following code: @ExceptionHandler(NestedServletException.class) public ModelAndView handleServletErrors(){ System.out.println("Servlet Exception is thrown"); ModelAndView mv = new ModelAndView("error"); mv.addObject("error", "Error encountered while processing reqeust."); return

Split string with LINQ

和自甴很熟 提交于 2019-12-10 15:23:11
问题 I want to order by my results with the matches count in my string line. So here is code .ThenByDescending(p => p.Title.ToLower() .Split(' ') .Count(w => words.Any(w.Contains))); But it bring me error and says that LINQ can't parse Split into SQL. LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method, and this method cannot be translated into a store expression. How can I implement Split via LINQ? For example, for this array it must order in this way words = {

Exception-handling antipatterns [closed]

半世苍凉 提交于 2019-12-10 15:19:18
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . Exception handling is a challenge for new and experienced developers alike. What are some examples of exception handling antipatterns that people have seen? 回答1: Bad cleanup logic Throwing in clean up code from a destructor. This one is doubly bad, because a.) throwing from a

how to catch an unhandled exception in c#?

谁说胖子不能爱 提交于 2019-12-10 15:17:37
问题 I'm trying to catch any unhandeled Exception in my program, i use this code in the Program main class static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.Run(new Form1()); } public static void

DRY With Different Try Statements and Identical Catch Statements

两盒软妹~` 提交于 2019-12-10 14:59:59
问题 So I have the following block of code inside a method: (all variables are local) // ... try { if (postXml != null) using (StreamWriter writer = new StreamWriter(req.GetRequestStream())) writer.Write(postXml.ToString()); } catch (WebException ex) { HttpWebResponse response = ex.Response as HttpWebResponse; if (response != null) result = HandleOtherResponse(response, out status); else result = HandleBadResponse(ex.ToString(), out status); } catch (Exception ex) { result = HandleBadResponse(ex

IPython behavior different for .py and .ipy files despite script being “pure” python (custom exception handler hook stops working)

こ雲淡風輕ζ 提交于 2019-12-10 14:57:53
问题 I have written an exception handler that is meant to log all uncaught exceptions in the code before calling the normal python exception hooks. Python and iPython have slightly different ways of doing this. What i have found is that the iPython way of doing it only works when run from within an interactive session, or when using a ".ipy" filename extension, despite the fact that I don't believe i am using any 'Magic,' and the regular python way of doing it won't work within ipython even if the

Catching exceptions that don't inherit from Exception

痞子三分冷 提交于 2019-12-10 14:57:42
问题 I have a database access module that I call with a query or a command. It figures out what to do with the database, and tries to do it. But, for instance if the query or command string is pathological, the call to the underlying PGDB module can throw an exception. Some incredibly useful information is returned by PGDB (from PostgreSQL under that), specifically calling out what errors were found in the query or command. This kind of usage of PGDB's various functions retrieves that information:

Debugging TargetInvocationException

五迷三道 提交于 2019-12-10 14:54:07
问题 I'm using Visual Studio 2008 (C# Express Edition) and I'm trying to debug a TargetInvocationException that occurs as a result of an event that I trigger. My question isn't specificly about this exception, (hence why I've not included any detail about this exception), but more about using the IDE effectively to debug this. I can see the inner exception gives me the detail I need to debug the error (clicking on 'View Detail' in the exception helper), but being fairly lazy, or should I say,