exception-handling

declare a method always throws an exception?

女生的网名这么多〃 提交于 2019-12-13 12:24:35
问题 I have a method like... int f() { try { int i = process(); return i; } catch(Exception ex) { ThrowSpecificFault(ex); } } This produces a compiler error, "not all code paths return a value". But in my case ThrowSpecificFault() will always throw (the appropriate) exception. So I am forced to a put a return value at the end but this is ugly. The purpose of this pattern in the first place is because "process()" is a call to an external web service but need to translate a variety of different

handling unchecked exceptions globally in project [closed]

99封情书 提交于 2019-12-13 10:27:05
问题 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 5 years ago . I an an telephonic interview of java the interviewer asked few questions regarding java exceptions in which one of the question he asked is How can you handle unchecked exceptions globally in project.? now for this even i have to think for a moment by defining the custom error

Use jmp_buf in multiple file

佐手、 提交于 2019-12-13 09:10:37
问题 For clearly, please view my sample I have two files: main.cpp and myfunction.h This is main.cpp #include <setjmp.h> #include <myfunction.h> int main() { if ( ! setjmp(bufJum) ) { printf("1"); func(); } else { printf("2"); } return 0; } This is myfunction.h #include <setjmp.h> static jmp_buf bufJum; int func(){ longjum(bufJum, 1); } Now, I want my screen print "1" and then print "2", but this code is uncorrect! Please, help me! Thank you so much! 回答1: If you want to have it in multiple files,

Null Exception handling in foreach loop

不想你离开。 提交于 2019-12-13 08:56:41
问题 I am having the list X with some string and null value . I am iterating the foreach loop to bind the value to the textbox. If I get any null values in my list X the foreach loop get terminated and getting the null exception how to handle it. I am checking the condition inside the for each loop. but i tnink it not correct logcally. SPList _listObj = web.Lists[new Guid(listID)]; SPListItem item = _listObj.GetItemById(Convert.ToInt32(itemID)); foreach (SPField field in _listObj.Fields) { if

How to write trycatch in R

与世无争的帅哥 提交于 2019-12-13 07:09:51
问题 I want to write trycatch code to deal with error in downloading from the web. url <- c( "http://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html", "http://en.wikipedia.org/wiki/Xz") y <- mapply(readLines, con=url) These two statements run successfully. Below, I create a non-exist web address: url <- c("xxxxx", "http://en.wikipedia.org/wiki/Xz") url[1] does not exist. How does one write a trycatch loop (function) so that: When the URL is wrong, the output will be: "web URL is

Junit assert something after awaiting and handling an exception

萝らか妹 提交于 2019-12-13 06:52:26
问题 method which throws at first and second call: public void foo() throws Exception test: @test public void testFooThrowsAtFirstAndSecondTime(){ boolean thrown; try { foo(); } catch (Exception e) { thrown = true; } assertTrue(thrown); thrown = false; try { foo(); } catch (Exception e) { thrown = true; } assertTrue(thrown); foo(); } Could you help me find a better solution for this? Use of Mockito for a better solution would be also acceptable. With better i mean, if i could avoid try/catch or

Should I throw a KeyNotFoundException for a database lookup? [closed]

依然范特西╮ 提交于 2019-12-13 06:25:27
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I've got some code that, given an ID, returns an item from the database. If no item matches the given ID, is it appropriate to throw a KeyNotFoundException, or are such exceptions meant only for Dictionary types? 回答1: Depending on the framework you're using to access the

How to handle TIdHTTP fatal network errors without interrupting thread's execution?

对着背影说爱祢 提交于 2019-12-13 05:51:50
问题 I'd like to elaborate on how to properly handle fatal network exceptions raised by TIdHTTP inside TThread's Execute procedure. My app runs a while..do loop inside the Execute procedure. Each loop makes a TIdHTTP.Get() call. The exceptions are handled at the loop level. There is also an upper level handler of on E: Exception do (level of Execute ). The scenario assumes a fatal network error during active network operations (i.e. adapter outage, "connection reset by peer", etc.). 10 threads are

Exception Handling doesn't work

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 05:51:04
问题 I am trying to use try-catch blocks to handle a divide-by-zero exception in marmalade, but I guess marmalade overrides c++ exception handling, so it's not working. I've searched on the forums and the solution seems to be that I have to add one option in the mkb as explained in this post. options { enable-exceptions=1 } I already tried adding it, but it's not working too. Is there any way I can handle this exception? 回答1: If you are writing an extension for the marmalade exceptions will not

Matlab minimum working example of handling exception higher up in call stack?

只愿长相守 提交于 2019-12-13 05:38:49
问题 I've been browsing Matlab's exception handling pages, and having a bit of difficulty finding a complete minimum working example of an exception being handled by a function in the call stack that is above where the exception is generated. Would anyone be able to point to such a page, or confirm that it is lacking? Thanks. 回答1: I had in mind something like the following minimum working example, showing the mechanics in handing an error from an invoked function to a caller. TMW agrees that