exception-handling

why does throw “nothing” causes program termination?

一笑奈何 提交于 2019-12-18 03:57:50
问题 const int MIN_NUMBER = 4; class Temp { public: Temp(int x) : X(x) { } bool getX() const { try { if( X < MIN_NUMBER) { //By mistake throwing any specific exception was missed out //Program terminated here throw ; } } catch (bool bTemp) { cout<<"catch(bool) exception"; } catch(...) { cout<<"catch... exception"; } return X; } private: int X; }; int main(int argc, char* argv[]) { Temp *pTemp = NULL; try { pTemp = new Temp(3); int nX = pTemp->getX(); delete pTemp; } catch(...) { cout<<"cought

why does throw “nothing” causes program termination?

白昼怎懂夜的黑 提交于 2019-12-18 03:57:16
问题 const int MIN_NUMBER = 4; class Temp { public: Temp(int x) : X(x) { } bool getX() const { try { if( X < MIN_NUMBER) { //By mistake throwing any specific exception was missed out //Program terminated here throw ; } } catch (bool bTemp) { cout<<"catch(bool) exception"; } catch(...) { cout<<"catch... exception"; } return X; } private: int X; }; int main(int argc, char* argv[]) { Temp *pTemp = NULL; try { pTemp = new Temp(3); int nX = pTemp->getX(); delete pTemp; } catch(...) { cout<<"cought

Will finally blocks be executed if returning from try or catch blocks in C#? If so, before returning or after?

ε祈祈猫儿з 提交于 2019-12-18 03:17:12
问题 No content available! 回答1: Yes, the finally block is executed however the flow leaves the try block - whether by reaching the end, returning, or throwing an exception. From the C# 4 spec, section 8.10: The statements of a finally block are always executed when control leaves a try statement. This is true whether the control transfer occurs as a result of normal execution, as a result of executing a break, continue, goto, or return statement, or as a result of propagating an exception out of

Performance cost of coding “exception driven development” in Java?

自作多情 提交于 2019-12-18 02:34:47
问题 Are there are any performance cost by creating, throwing and catching exceptions in Java? I am planing to add 'exception driven development' into a larger project. I would like to design my own exceptions and include them into my methods, forcing developers to catch and do appropriate work. For example, if you have a method to get a user from the database based on a name. public User getUser(String name); However, it is possible that the user might be null and it is common to forget to check

Catching Unhandled Exceptions in Child Threads in WPF

落花浮王杯 提交于 2019-12-18 02:09:19
问题 I have a WPF application that spins off several threads. I have defined a DispatcherUnhandledException event handler in App.xaml.cs that displays a detailed error message, and this handler gets called every time the UI thread encounters an exception. The problem is with the child threads: their unhandled exceptions never get handled. How do I do this? Sample code: private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading

How can I improve this exception retry scenario?

本小妞迷上赌 提交于 2019-12-17 23:22:48
问题 I have a web service method I am calling which is 3rd party and outside of my domain. For some reason every now and again the web service fails with a gateway timeout. Its intermittent and a call to it directly after a failed attempt can succeed. Now I am left with a coding dilemma, I have code that should do the trick, but the code looks like amateur hour, as you'll see below. Is this really bad code, or acceptable given the usage? If its not acceptable, how can I improve it? Please try hard

How to write multiple try statements in one block in python?

我的梦境 提交于 2019-12-17 23:08:16
问题 I want to do: try: do() except: do2() except: do3() except: do4() If do() fails, execute do2(), if do2() fails too, exceute do3() and so on. best Regards 回答1: I'd write a quick wrapper function first() for this. usage : value = first([f1, f2, f3, ..., fn], default='All failed') #!/usr/bin/env def first(flist, default=None): """ Try each function in `flist` until one does not throw an exception, and return the return value of that function. If all functions throw exceptions, return `default`

try catch statement in PHP where the file does not upload

泪湿孤枕 提交于 2019-12-17 22:56:50
问题 I understand what try-catch statements do, but from reading the documentation on php.net, I would not be able to implement one into my own code. I need a real example to help me understand. How can I turn this example into a try catch statement, if the upload was not successful? $move = move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/uploads/".$_FILES['file']['name']); if (!$move) { die ('File didn't upload'); } else { //opens the uploaded file for extraction echo

Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IList'

泪湿孤枕 提交于 2019-12-17 22:45:08
问题 I have a method: public DzieckoAndOpiekunCollection GetChildAndOpiekunByFirstnameLastname(string firstname, string lastname) { DataTransfer.ChargeInSchoolEntities db = new DataTransfer.ChargeInSchoolEntities(); DzieckoAndOpiekunCollection result = new DzieckoAndOpiekunCollection(); if (firstname == null && lastname != null) { IList<DzieckoAndOpiekun> resultV = from p in db.Dziecko where lastname == p.Nazwisko **select** new DzieckoAndOpiekun( p.Imie, p.Nazwisko, p.Opiekun.Imie, p.Opiekun

How to catch Errno::ECONNRESET class in “case when”?

佐手、 提交于 2019-12-17 22:38:17
问题 My application (Ruby 1.9.2) may raise different exceptions, including net-connection breaks. I rescue Exception => e , then do case/when to handle them in defferent ways, but several errors go through my cases straight to else . rescue Exception => e p e.class case e.class when Errno::ECONNRESET p 1 when Errno::ECONNRESET,Errno::ECONNABORTED,Errno::ETIMEDOUT p 2 else p 3 end end Prints: Errno::ECONNRESET 3 回答1: This is because of how the === operator works on the class Class The case