exception-handling

How to handle exceptions when we give no argument to a C executable program [duplicate]

心已入冬 提交于 2019-12-24 19:16:50
问题 This question already has answers here : getopt fails to detect missing argument for option (5 answers) Closed 6 years ago . I have this C program in which it should be given arguments like the following: ./program -i inputFile -o outputFile and here's my related section of code while ((c = getopt(argc, argv, "i:o:")) != -1) { switch (c) { case 'i': inFile = strdup(optarg); break; case 'o': outFile = strdup(optarg); break; default: error_usage(argv[0]); } } also here's the error_usage

How do i get data from null JSONObject?

谁说我不能喝 提交于 2019-12-24 19:06:43
问题 This is my first Question on StackOverflow, So sorry for bad representation of the question. Here is Json in logcat : I/Result is: null{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":300,"main":"Drizzle","description":"light intensity drizzle","icon":"09d"}],"base":"stations","main":{"temp":280.32,"pressure":1012,"humidity":81,"temp_min":279.15,"temp_max":281.15},"visibility":10000,"wind":{"speed":4.1,"deg":80},"clouds":{"all":90},"dt":1485789600,"sys":{"type":1,"id":5091,"message":0.0103

Correct use of Try Catch for the SQL connection in C#

别说谁变了你拦得住时间么 提交于 2019-12-24 18:51:43
问题 Is this code correct in means of Try/Catch? I need to value whether the action is done or not to inform the user about the result, so I will then get the bool value to know if connection was successful. public static bool CreateSQLDatabaseTable() { var connString = "Server=localhost\\SQLEXPRESS;Integrated Security = SSPI; database = MyDB"; string cmdText = "SELECT count(*) as Exist from INFORMATION_SCHEMA.TABLES where table_name =@Product"; try { using (var sqlConnection = new SqlConnection

Execute code block if condition or exception

社会主义新天地 提交于 2019-12-24 18:45:59
问题 With exceptions being so central to idiomatic Python, is there a clean way to execute a particular code block if an expression evaluates to True or the evaluation of the expression raises an exception? By clean, I mean an easy-to-read, Pythonic, and not repeating the code block? For example, instead of: try: if some_function(data) is None: report_error('Something happened') except SomeException: report_error('Something happened') # repeated code can this be cleanly rewritten so that report

where does the actual code of exception handler reside in Linux?

ε祈祈猫儿з 提交于 2019-12-24 18:18:16
问题 This is from my textbook that describes how processor trigger exception handler: and it says that: The processor then triggers the exception by making an indirect procedure call, through entry k of the exception table, to the corresponding handler. Figure 8.3 shows how the processor uses the exception table to form the address of the appropriate exception handler. The exception number is an index into the exception table, whose starting address is contained in a special CPU register called

Check if WCF(namedpipes) host is available?

廉价感情. 提交于 2019-12-24 18:02:24
问题 Hi, We have a winform application that is only to be executed as a singelton, If a second instance try to start this new instance will connect to the current and transmit parameters over namedpipes. The problem is that when starting the first instance there will be a try to connect to existing host. If the host is not existing(like in this case) an exception will be thrown. There is no problem to handle this exception but our developers is often using "Break on Exception" and that means that

Check if WCF(namedpipes) host is available?

醉酒当歌 提交于 2019-12-24 18:01:55
问题 Hi, We have a winform application that is only to be executed as a singelton, If a second instance try to start this new instance will connect to the current and transmit parameters over namedpipes. The problem is that when starting the first instance there will be a try to connect to existing host. If the host is not existing(like in this case) an exception will be thrown. There is no problem to handle this exception but our developers is often using "Break on Exception" and that means that

According to a knowledgeable author within the C++ community, the code shown below should not compile. Is he wrong?

微笑、不失礼 提交于 2019-12-24 17:52:46
问题 According to Herb Sutter the code below wouldn't compile. See this site http://www.gotw.ca/gotw/066.htm from where I've extracted the following text, regarding function-try-blocks : Toward Some Morals Incidentally, this also means that the only (repeat only) possible use for a constructor function-try-block is to translate an exception thrown from a base or member subobject. That's Moral #1. Next, Moral #2 says that destructor function-try-blocks are entirely usele-- "--But wait!" I hear

According to a knowledgeable author within the C++ community, the code shown below should not compile. Is he wrong?

这一生的挚爱 提交于 2019-12-24 17:51:04
问题 According to Herb Sutter the code below wouldn't compile. See this site http://www.gotw.ca/gotw/066.htm from where I've extracted the following text, regarding function-try-blocks : Toward Some Morals Incidentally, this also means that the only (repeat only) possible use for a constructor function-try-block is to translate an exception thrown from a base or member subobject. That's Moral #1. Next, Moral #2 says that destructor function-try-blocks are entirely usele-- "--But wait!" I hear

Handles SQL Exception from Entity Framework

我是研究僧i 提交于 2019-12-24 17:50:36
问题 In my sql stored procedure, i do some insertion and updating which in some scenarios throws Primary Key or unique key violation. When I try to execute this procedure from ADO.net, .net application also throws that exception and let me know that something wrong had happen. But when I try to execute this procedure from EF, it just executes. Neither it show anything nor update anything. How should I handle or notify user that something wrong had happen? Ado.Net code is SqlConnection