try-catch

Swift 2.0 exception handling

蹲街弑〆低调 提交于 2019-12-13 02:12:17
问题 We want to know error handling mechanism in SWIFT for whole block of code. As, in swift, there are some techniques used for error handling, some of them are like using guard or if let . Also we can achieve it using do - catch statement. But we are getting stuck while handling error for whole bunch of code using single try-catch block as we were doing in Objective-C . In Objective-C this block was easily handling errors within any line of code in it. So we want to know this type of mechanism

Get overall hours from two time picker

六月ゝ 毕业季﹏ 提交于 2019-12-13 01:37:17
问题 What is the best way to get the overall total hours from two time picker? I have two different time picker, each time picker has time in and time out. The coding below works fine if the two time picker has filled but doesn't work if only one time picker is filled. Any suggestions would greatly appreciated. SimpleDateFormat format = new SimpleDateFormat("HH:mm"); Date dateb = null; //time in Date datec = null; //time out Date dateb1 = null; //time in1 Date datec1 = null; // time out2 try {

Monad to catch multiple exceptions (not just fail on single)

孤街醉人 提交于 2019-12-13 00:15:31
问题 I have a similar question to what is asked here (Multiple or Single Try Catch), however in my case I need to follow this pattern for functional (and not performance reasons) Essentially I am handling parameter errors in Scalatra, and I need an easy way to catch if any conversions fail without the first failure skipping the rest of the try calls In other words, I need something that follows a pattern like this def checkMultiple(a:Seq[Try]):Either[Map[_,Throwable],Map[_,Success]] = { ??? } I

Avoiding index out of bounds exceptions

爱⌒轻易说出口 提交于 2019-12-12 23:27:45
问题 I am using an Array List to store data about moving objects on screen. I suspect this is because my renderer and my logic are running on separate threads, but sometimes when data is removed from the list I get an indexOutOfBoundsException. I have taken all the steps I can think of to avoid this including try/catch but the exception still sometimes occurs. This is the part of my renderer thread that seems to cause the exception. public void drawMobs(GL10 gl) { boolean playing =

Show all functions that throw exceptions

二次信任 提交于 2019-12-12 21:04:28
问题 I am working on a Java program and I was wondering if there was some tool in Eclipse that would point out all of the methods that throw exceptions. I just want to make sure that I got all of them. Thanks for the help, Dan 回答1: Checked exception must be caught so Eclipse will tell you about them. On the other hand unchecked exception (aka RuntimeException) are "not supposed to happen", it's most of the time a programming problem. Hence Java doesn't require to catch them and AFAIK Eclipse will

How do I Throw an IllegalArgumentException that won't terminate my program?

烂漫一生 提交于 2019-12-12 18:18:09
问题 Ok so I have a method with a switch statement but I left out the rest of the cases because they're not important. In my main method, the operator method is called and passed the parameter "selection" in a while loop until they choose "Q". When the user enters a negative number, it should throw an exception, print a message, and ignore their input but then loop back to the beginning. When this exception is thrown it terminates the program. Any help would be very much appreciated. Thanks!

javascript try catch not fully working in firefox

ⅰ亾dé卋堺 提交于 2019-12-12 15:25:28
问题 Can someone explain me why this: <html> <head></head> <body> <script> try { document.attribute-withminus = 5; } catch(e) { alert('something went wrong'); } alert('ok'); </script> </body> </html> Doesn't give me an alert with 'something went wrong' and also no alert with 'ok'? It works fine in chrome. But in firefox, it just exits (it does show an error in the web console). The whole point of that try-catch is to make sure that if I type something wrong, it should give me an alert saying so. I

Is it legal and possible to access the return value in a finally block?

我只是一个虾纸丫 提交于 2019-12-12 14:40:01
问题 I wish to set a usererror string before leaving a function, depending on the return code and variable in the function. I currently have: Dim RetVal as RetType try ... if ... then RetVal = RetType.FailedParse end try endif ... finally select case RetVal case ... UserStr = ... end select end try return RetVal Is it possible to use return RetType.FailedParse, then access this in the finally block? 回答1: The only real way of doing this in C# would be to declare a variable at the start of the

In a MFC application, where to put a topmost try/catch?

ぃ、小莉子 提交于 2019-12-12 12:08:10
问题 In a MFC application, where to put a topmost try/catch? I have a MFC application and I would like to catch all the exceptions and show my own message box. This is my idea for a topmost try/catch block: try { // What enclose here? Or, where to put this try/catch block? } catch( const std::exception& e ) { ::MessageBox(0,e.what(),"I do not know hot to handle this exception, I will terminate",MB_OK); } catch(...) { ::MessageBox(0,"Unknown Excpetion","I do not know hot to handle this exception, I

jquery hides simple javascript errors

大城市里の小女人 提交于 2019-12-12 11:32:48
问题 I'm using jQuery and flot in chrome and firefox. As I work on my code, I find that execution silently fails on stupid stuff like accessing non-existent hash structures and the like. It feels like there is some try {} catch {} logic within jQuery that keeps me from seeing any errors. Any pointers on how to get around this without blanket hack-n-slash to isolate where a simple bug is? jshint hasn't been too helpful. --edit-- more debugging shows a trend. I'm basically finding typos (undefined