exception-handling

Using bool (return Type) to handle exceptions or pass exception to client?

爱⌒轻易说出口 提交于 2020-01-01 10:51:11
问题 I am trying to find out the best way of handling exceptions, I have a number of layers to my application and started to use a return type of BOOL i.e. if it fails then return False and if it succeeds return True.. This works great in methods like SaveMyRecord(somerecord); as i am passing in values and don't require anything returned so i can use the return type of bool to indicate if it succeeds or not. But then it got me thinking that things like GetMyRecord() actually returns type of

How to handle exceptions from C++ via SWIG to Java

这一生的挚爱 提交于 2020-01-01 09:40:05
问题 We are implementing a wrapper on C++ code for exposure to Java clients. I have seen the SWIG documents about exception handling but what does this translate to in coding terms in the three layers (C++/SWIG/Java)? If anybody has working example(s) or advice, I would be grateful. 回答1: Since I've wrestled with this (see my blog from my profile, it's on python, SWIG, exceptions and directors but should help) let me give you a few pieces of advice: Don't send C++ exceptions up to the Java stack.

Understanding try..catch in Javascript

你说的曾经没有我的故事 提交于 2020-01-01 09:17:47
问题 I have this try and catch problem. I am trying to redirect to a different page. But sometimes it does and some times it doesnt. I think the problem is in try and catch . can someone help me understand this. Thanks var pg = new Object(); var da = document.all; var wo = window.opener; pg.changeHideReasonID = function(){ if(pg.hideReasonID.value == 0 && pg.hideReasonID.selectedIndex > 0){ pg.otherReason.style.backgroundColor = "ffffff"; pg.otherReason.disabled = 0; pg.otherReason.focus(); } else

Catch Exception of AsyncTask. Need Thinking

邮差的信 提交于 2020-01-01 09:05:30
问题 I want to catch exception of a thread in doInBackground and print the error message in onPostExcecute. The problem is I don't have the Throwable object in onPostExecute. How to catch Exception in non-UI thread and print the error message in UI-thread ? public class TestTask extends AsyncTask<Void, Void, List<String>> { @Override protected List<String> doInBackground(final Void... params) { try { ... return listOfString; } catch(SomeCustomException e) { ... return null; } } @Override protected

What is the purpose of a function try block? [duplicate]

試著忘記壹切 提交于 2020-01-01 08:49:32
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: When is a function try block useful? Difference between try-catch syntax for function This code throws an int exception while constructing the Dog object inside class UseResources . The int exception is caught by a normal try-catch block and the code outputs : Cat() Dog() ~Cat() Inside handler #include <iostream> using namespace std; class Cat { public: Cat() { cout << "Cat()" << endl; } ~Cat() { cout << "~Cat()

Why did Go add panic and recover in addition to error handling? [closed]

不打扰是莪最后的温柔 提交于 2020-01-01 08:28:45
问题 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 last year . Why did Go end up adopting exception handling with panic/recover, when the language is so idiomatic and a strong advocate of error codes? What scenarios did the designers of Go envision not handled by error codes and necessitate panic/recover? I understand convention says limit

Handling exceptions from urllib2 and mechanize in Python

余生颓废 提交于 2020-01-01 07:20:56
问题 I am a novice at using exception handling. I am using the mechanize module to scrape several websites. My program fails frequently because the connection is slow and because the requests timeout. I would like to be able to retry the website (on a timeout, for instance) up to 5 times after 30 second delays between each try. I looked at this stackoverflow answer and can see how I can handle various exceptions. I also see (although it looks very clumsy) how I can put the try/exception inside a

WPF: Handling Corrupt Font Cache

两盒软妹~` 提交于 2020-01-01 05:07:07
问题 I have a WPF app (.NET 3.5) that is generally run on our client's XP machines. Over the past 5 months, there have been three occasions where a corrupt font cache causes the application to stop responding on load. Deleting the font cache per these instructions does solve the immediate issue. However, I would like to find a way to either help prevent such corruption to begin with (most of what I've read suggests it has to do with updated video drivers without a reboot after?), or have my

Removing excessive try-catch blocks

早过忘川 提交于 2020-01-01 04:47:13
问题 I'm refactoring a medium-sized WinForms application written by other developers and almost every method of every class is surrounded by a try-catch block. 99% of the time these catch blocks only log exceptions or cleanup resources and return error status. I think it is obvious that this application lacks proper exception-handling mechanism and I'm planning to remove most try-catch blocks. Is there any downside of doing so? How would you do this? I'm planning to: To log exceptions

SQLiteConstraintException dont go inside catch

风格不统一 提交于 2020-01-01 04:40:06
问题 When I run that code I have inside the db.insert an exception: 08-29 15:40:17.519: E/SQLiteDatabase(3599): android.database.sqlite.SQLiteConstraintException: column date is not unique (code 19) Which is normal, because I already have that value as a key. So in that case I do a catch of SQLiteConstraintException but I never get inside the catch when I run the code. What am I doing wrong? try { db.insert(TABLE_STATISTICS, null, values); } catch (SQLiteConstraintException e) { Log.d("entered",