exception-handling

If you catch an exception by reference, can you modify it and rethrow?

扶醉桌前 提交于 2019-12-20 11:35:11
问题 Does the standard have anything to say about an exception that is caught by reference and what happens to attempts to modify it? Consider the following code: class my_exception: public std::logic_error { public: std::vector<std::string> callstack; }; void MyFunc() { try { SomethingThatThrows(); } catch (my_exception & e) { e.callstack.push_back("MyFunc"); throw; } } This is a contrived example, I'm not actually attempting something like this. I was just curious what would happen, based on the

.NET exception caught is unexpectedly null

假如想象 提交于 2019-12-20 11:06:52
问题 See below for an explanation of what is going on I have a really weird issue where the exception caught is null. The code uses MEF and tries hard to report composition errors. Using the debugger I can see the exception being thrown (an InvalidOperationException ) but when it is caught by the last catch block in the code below the ex variable is null. This is true both in the debugger and when executing the code normally. static T ResolveWithErrorHandling<T>() where T : class { try {

Should I check for DB constraints in code or should I catch exceptions thrown by DB

╄→尐↘猪︶ㄣ 提交于 2019-12-20 10:43:53
问题 I have an application that saves data into a table called Jobs. The Jobs table has a column called Name which has a UNIQUE constraint. The Name column is not PRIMARY KEY. I wonder if I should check for duplicate entries myself before I try to save/update a new entry or if it's better to wait for an exception thrown by the data access layer. I'm using NHibernate for this App if it's of any importance Thanks to everybody for the great input. I have found one more reason why I should validate in

Best way to check whether a certain exception type was the cause (of a cause, etc …) in a nested exception?

浪子不回头ぞ 提交于 2019-12-20 10:34:18
问题 I am writing some JUnit tests that verify that an exception of type MyCustomException is thrown. However, this exception is wrapped in other exceptions a number of times, e.g. in an InvocationTargetException, which in turn is wrapped in a RuntimeException. What's the best way to determine whether MyCustomException somehow caused the exception that I actually catch? I would like to do something like this (see underlined): try { doSomethingPotentiallyExceptional(); fail("Expected an exception."

Catch exception in node during JSON.parse

扶醉桌前 提交于 2019-12-20 10:17:48
问题 My node server dies when it is unable to parse JSON in the following line: var json = JSON.parse(message); I read this thread on how to catch exceptions in node, but I am still not sure what is the proper way to wrap a try and catch block around this statement. My goal is to catch the exception and log an error to the console, and of course keep the server alive. Thank you. 回答1: It's all good! :-) JSON.parse runs synchronous and does not know anything about an err parameter as is often used

JSF 1.x generic exception handling

霸气de小男生 提交于 2019-12-20 10:12:10
问题 If I have an exception in my business layer (e.g. a SQL exception in my JDBC connection bean), how can I propagate it with a custom message to a global error.jsp page? 回答1: JSF 1.x doesn't provide any implicit error handling of this type, though you can redirect to an error page using navigation rules (assuming a form post)... <navigation-case> <description> Handle a generic error outcome that might be returned by any application Action. </description> <display-name>Generic Error Outcome<

Why win32 exception are not caught by c# exception handling mechanism

随声附和 提交于 2019-12-20 09:59:31
问题 I have a winforms application.Winforms start with Program.cs where we have main() defined.I have put this code in try-catch block. [STAThread] static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmSplash()); } catch (Exception ex) { MessageBox.Show(ex.Message); if (ex.InnerException != null) { MessageBox.Show(ex.InnerException.ToString()); } } } Whenever there is a win32 exception,this mechanism fails and

Selenium 2 and JUnit4: How to capture screenshot on exception?

柔情痞子 提交于 2019-12-20 09:38:27
问题 I want to capture a screenshot only upon unexpected exception. 回答1: Note.- This answer could be outdated. The answer is based on Selenium 2.15 Using TestWatcher does the trick (the unit test must extend following BaseTest ): public abstract class BaseTest { // ... protected WebDriver driver; @Rule public TestRule testWatcher = new TestWatcher() { @Override public void starting(Description desc) { LOG.info("Launching browser..."); driver = Utils.getFirefoxDriver(); } @Override public void

WCF Contract Name 'IMyService' could not be found?

[亡魂溺海] 提交于 2019-12-20 09:09:28
问题 The contract name 'IMyService' could not be found in the list of contracts implemented by the service 'MyService'.. ---> System.InvalidOperationException: The contract name 'IMyService' could not be found in the list of contracts implemented by the service 'MyService'. This is driving me crazy. I have a WCF web service that works on my dev machine, but when I copy it to a Virtual Machine that I am using for testing, I get the error that seems to indicate that I am not implementing the

Exception Handling in .net web apps

瘦欲@ 提交于 2019-12-20 08:50:27
问题 I admit it: I don't bother with too much exception handling. I know I should do more but I can never wrap my head around where to start and where to stop. I'm not being lazy. Far from it. It's that I'm overwrought with exception handling ambivalence. It just seems that there is a seemingly infinite number of places in even the smallest app where exception handling can be applied and it can begin to feel like overkill. I've gotten by with careful testing, validating, and silent prayer but this