exception-handling

Web Api on Azure shows no error detail using 'return InternalServerError(ex)'

本小妞迷上赌 提交于 2019-12-05 16:58:56
问题 My Web Api when run locally (in Release mode) will return any errors in this format: { "Message": "An error has occurred.", "ExceptionMessage": "No text specified", "ExceptionType": "System.Exception", "StackTrace": null } But after deployment/publish to an Azure VM, only this remains: { "Message": "An error has occurred." } API code: try { var msg = ... new MessageService().SaveMessage(msg)); // <-- does some checks; may throw. return Ok(); } catch (Exception ex) { return InternalServerError

Does Java declare “throws Exception” by default?

喜夏-厌秋 提交于 2019-12-05 16:48:18
问题 Consider following classes: class X { public void met() { } } and class Y extends X { public void met() throws NullPointerException { throw new NullPointerException(); } } From what I have read on other questions ( Why can't overriding methods throw exceptions broader than the overridden method? and Java method throwing exception ) I understand that the overriding method in the subclass, has to throw either the same or a subclass of the exception thrown in the overridden method. Do Java

Throw VS rethrow : same result?

怎甘沉沦 提交于 2019-12-05 16:43:33
问题 refering to a lot of documentation on the net, particularly on SO, eg : What is the proper way to re-throw an exception in C#? there should be a difference between "throw e;" and "throw;". But, from : http://bartdesmet.net/blogs/bart/archive/2006/03/12/3815.aspx, this code : using System; class Ex { public static void Main() { // // First test rethrowing the caught exception variable. // Console.WriteLine("First test"); try { ThrowWithVariable(); } catch (Exception ex) { Console.WriteLine(ex

Does it make sense to catch ThreadAbortException and perform no action?

随声附和 提交于 2019-12-05 16:29:42
问题 catch (ThreadAbortException) { } catch (Exception ex) { TraceManager.TraceException(ex, (int)ErrorCode.GENERIC_EXCEPTION, ex.StackTrace + "\n" + ex.Message + "\n" + VendorUrl); } does it make sense to even have the catch (ThreadAbortException) { } or will that cause the ThreadAbortException to be swallowed and lost forever? 回答1: ThreadAbortException cannot be caught "completely"; it will automatically be rethrown at the end of the catch block (see the linked MSDN docs page) unless Thread

Function exceptions specification and standard exceptions - foo() throw(Exception)

妖精的绣舞 提交于 2019-12-05 16:06:15
In C++ you may declare function with exception specification like this: int foo() const throw(Exception); I found those two links: http://www.cplusplus.com/doc/tutorial/exceptions/ and http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr156.htm But several things end up unanswered... Question 1: why to add exception specification? Will it bring any performance increase? What will be different for compiler? Because it seems just like an information for programmer to me. Question 2: what will happend (what should happen) if I

C++ Do I need to write throw clause for a function everywhere?

我怕爱的太早我们不能终老 提交于 2019-12-05 15:57:13
Before Consider to have a class and a global function: This is, for example, usefulfuncts.hpp void dosome(int a, int b) throw (std::exception); This is usefulfuncts.cpp void dosome(int a, int b) throw (std::exception) { //... } And this is aclass.hpp class aclass { // Members... friend void dosome(int a, int b) throw (std::exception); // Members... }; After (what I would like that to be) Ok! I would like to understand if it is strictly necessary to write everytime the throw clause. So for example can I do this? This is usefulfuncts.hpp void dosome(int a, int b) throw (std::exception); This is

AppDomain.UnhandledException handler doesn't fire in unit test

让人想犯罪 __ 提交于 2019-12-05 15:41:49
In the code snippet below, why wouldn't the attached handler (of AppDomain.CurrentDomain.UnhandledException event) fire up when an exception is thrown in the unit test? I'm using NUnit 2.5.10 with TestDriven.NET 3.0 on VS2010. [TestFixture] public class MyTests { private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine("Gotcha!"); } [Test] public void ExceptionTest1() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; throw new Exception("ExceptionInTest"); } } Output: (No gotchas) ------ Test started:

Navigation from managed bean constructor in ADF Faces JSF 1.2

落爺英雄遲暮 提交于 2019-12-05 15:23:04
Is it possible to navigate to another page/view from the constructor of the managed bean? I want this redirection if any exception occurred. I have tried many ways: Try-1: getFacesContext().responseComplete(); getFacesContext().getApplication().getNavigationHandler().handleNavigation(getFacesContext(), null, "gotoPartError"); getFacesContext().renderResponse(); Try-2: getServletResponse().sendRedirect("partError.jspx") Try-3: getFacesContext().responseComplete(); getFacesContext().getExternalContext().redirect(getServletRequest().getContextPath() + "/pages/partError.jspx"); Try-4:

Does IExceptionLogger deprecate the need for ExceptionFilterAttribute in Web API 2?

核能气质少年 提交于 2019-12-05 14:51:16
问题 Following the discussion from the official documentation on implementing an IExceptionLogger (http://www.asp.net/web-api/overview/testing-and-debugging/web-api-global-error-handling) which links to the (now dated?) article on implementing an ExceptionFilterAttribute (http://www.asp.net/web-api/overview/testing-and-debugging/exception-handling), is there any reason to register a global ExceptionFilterAttribute if you register a service for IExceptionLogger ? I did and when debugging an

Can't catch native exception in managed code

拟墨画扇 提交于 2019-12-05 13:33:03
问题 I have a mixed .NET and native code console application. The application process is terminated due to Visual C RunTime Library fatal error. Even though I am using the following, the managed code doesn’t catch the native exception: Try/catch block AppDomain.UnHandledExption += ... Marking the RuntimeCompatibilityAttribute(WrapNonExceptionThrows = true) in the AssmblyInfo file. What else can I do? 回答1: Native exceptions have changed in .NET 4 so that they can not be catched with a standard