Search Results

Search found 19541 results on 782 pages for 'event handling'.

Page 70/782 | < Previous Page | 66 67 68 69 70 71 72 73 74 75 76 77  | Next Page >

  • Should java try blocks be scoped as tightly as possible?

    - by isme
    I've been told that there is some overhead in using the Java try-catch mechanism. So, while it is necessary to put methods that throw checked exception within a try block to handle the possible exception, it is good practice performance-wise to limit the size of the try block to contain only those operations that could throw exceptions. I'm not so sure that this is a sensible conclusion. Consider the two implementations below of a function that processes a specified text file. Even if it is true that the first one incurs some unnecessary overhead, I find it much easier to follow. It is less clear where exactly the exceptions come from just from looking at statements, but the comments clearly show which statements are responsible. The second one is much longer and complicated than the first. In particular, the nice line-reading idiom of the first has to be mangled to fit the readLine call into a try block. What is the best practice for handling exceptions in a funcion where multiple exceptions could be thrown in its definition? This one contains all the processing code within the try block: void processFile(File f) { try { // construction of FileReader can throw FileNotFoundException BufferedReader in = new BufferedReader(new FileReader(f)); // call of readLine can throw IOException String line; while ((line = in.readLine()) != null) { process(line); } } catch (FileNotFoundException ex) { handle(ex); } catch (IOException ex) { handle(ex); } } This one contains only the methods that throw exceptions within try blocks: void processFile(File f) { FileReader reader; try { reader = new FileReader(f); } catch (FileNotFoundException ex) { handle(ex); return; } BufferedReader in = new BufferedReader(reader); String line; while (true) { try { line = in.readLine(); } catch (IOException ex) { handle(ex); break; } if (line == null) { break; } process(line); } }

    Read the article

  • handling pointer to member functions within hierachy in C++

    - by anatoli
    Hi, I'm trying to code the following situation: I have a base class providing a framework for handling events. I'm trying to use an array of pointer-to-member-functions for that. It goes as following: class EH { // EventHandler virtual void something(); // just to make sure we get RTTI public: typedef void (EH::*func_t)(); protected: func_t funcs_d[10]; protected: void register_handler(int event_num, func_t f) { funcs_d[event_num] = f; } public: void handle_event(int event_num) { (this->*(funcs_d[event_num]))(); } }; Then the users are supposed to derive other classes from this one and provide handlers: class DEH : public EH { public: typedef void (DEH::*func_t)(); void handle_event_5(); DEH() { func_t f5 = &DEH::handle_event_5; register_handler(5, f5); // doesn't compile ........ } }; This code wouldn't compile, since DEH::func_t cannot be converted to EH::func_t. It makes perfect sense to me. In my case the conversion is safe since the object under this is really DEH. So I'd like to have something like that: void EH::DEH_handle_event_5_wrapper() { DEH *p = dynamic_cast<DEH *>(this); assert(p != NULL); p->handle_event_5(); } and then instead of func_t f5 = &DEH::handle_event_5; register_handler(5, f5); // doesn't compile in DEH::DEH() put register_handler(5, &EH::DEH_handle_event_5_wrapper); So, finally the question (took me long enough...): Is there a way to create those wrappers (like EH::DEH_handle_event_5_wrapper) automatically? Or to do something similar? What other solutions to this situation are out there? Thanks.

    Read the article

  • Exception handling in Spring MVC with 3 layer architecture

    - by Chorochrondochor
    I am building a simple web applications with 3 layers - DAO, Service, MVC. When in my Controller I want to delete menu group and it contains menus I am getting ConstraintViolationException. Where should I handle this exception? In DAO, Service, or in Controller? Currently I am handling the exception in Controller. My code below. DAO method for deleting menu groups: @Override public void delete(E e){ if (e == null){ throw new DaoException("Entity can't be null."); } getCurrentSession().delete(e); } Service method for deleting menu groups: @Override @Transactional(readOnly = false) public void delete(MenuGroupEntity menuGroupEntity) { menuGroupDao.delete(menuGroupEntity); } Controller method for deleting menu groups in Controller: @RequestMapping(value = "/{menuGroupId}/delete", method = RequestMethod.GET) public ModelAndView delete(@PathVariable Long menuGroupId, RedirectAttributes redirectAttributes){ MenuGroupEntity menuGroupEntity = menuGroupService.find(menuGroupId); if (menuGroupEntity != null){ try { menuGroupService.delete(menuGroupEntity); redirectAttributes.addFlashAttribute("flashMessage", "admin.menu-group-deleted"); redirectAttributes.addFlashAttribute("flashMessageType", "success"); } catch (Exception e){ redirectAttributes.addFlashAttribute("flashMessage", "admin.menu-group-could-not-be-deleted"); redirectAttributes.addFlashAttribute("flashMessageType", "danger"); } } return new ModelAndView("redirect:/admin/menu-group"); }

    Read the article

  • Any guidelines for handling the Headset and Bluetooth AVRC transport controls in Android 2.2

    - by StefanK
    I am trying to figure out what is the correct (new) approach for handling the Intent.ACTION_MEDIA_BUTTON in Froyo. In pre 2.2 days we had to register a BroadcastReceiver (either permanently or at run-time) and the Media Button events would arrive, as long as no other application intercepts them and aborts the broadcast. Froyo seems to still somewhat support that model (at least for the wired headset), but it also introduces the registerMediaButtonEventReceiver, and unregisterMediaButtonEventReceiver methods that seem to control the "transport focus" between applications. During my experiments, using registerMediaButtonEventReceiver does cause both the bluetooth and the wired headset button presses to be routed to the application's broadcast receiver (the app gets the "transport focus"), but it looks like any change in the audio routing (for example unplugging the headset) shits the focus back to the default media player. What is the logic behind the implementation in Android 2.2? What is correct way to handle transport controls? Do we have to detect the change in the audio routing and try to re-gain the focus? This is an issue that any 3rd party media player on the Android platform has to deal with, so I hope that somebody (probably a Google Engineer) can provide some guidelines that we can all follow. Having a standard approach may make headset button controls a bit more predictable for the end users. Stefan

    Read the article

  • How to use interfaces in exception handling

    - by vikp
    Hi, I'm working on the exception handling layer for my application. I have read few articles on interfaces and generics. I have used inheritance before quite a lot and I'm comfortable with in that area. I have a very brief design that I'm going to implement: public interface IMyExceptionLogger { public void LogException(); // Helper methods for writing into files,db, xml } I'm slightly confused what I should be doing next. public class FooClass: IMyExceptionLogger { // Fields // Constructors } Should I implement LogException() method within FooClass? If yes, than I'm struggling to see how I'm better of using an interface instead of the concrete class... I have a variety of classes that will make a use of that interface, but I don't want to write an implementation of that interface within each class. In the same time If I implement an interface in one class, and then use that class in different layers of the application I will be still using concrete classes instead of interfaces, which is a bad OO design... I hope this makes sense. Any feedback and suggestions are welcome. Please notice that I'm not interested in using net4log or its competitors because I'm doing this to learn. Thank you Edit: Wrote some more code. So I will implement variety of loggers with this interface, i.e. DBExceptionLogger, CSVExceptionLogger, XMLExceptionLogger etc. Than I will still end up with concrete classes that I will have to use in different layers of my application.

    Read the article

  • Task Parallel Library exception handling

    - by user1680766
    When handling exceptions in TPL tasks I have come across two ways to handle exceptions. The first catches the exception within the task and returns it within the result like so: var task = Task<Exception>.Factory.StartNew( () => { try { // Do Something return null; } catch (System.Exception e) { return e; } }); task.ContinueWith( r => { if (r.Result != null) { // Handle Exception } }); The second is the one shown within the documentation and I guess the proper way to do things: var task = Task.Factory.StartNew( () => { // Do Something }); task.ContinueWith( r => { if (r.Exception != null) { // Handle Aggregate Exception r.Exception.Handle(y => true); } }); I am wondering if there is anything wrong with the first approach? I have received 'unhandled aggregate exception' exceptions every now and again using this technique and was wondering how this can happen?

    Read the article

  • How to show useful error messages from a database error callback in Phonegap?

    - by Magnus Smith
    Using Phonegap you can set a function to be called back if the whole database transaction or the individual SQL statement errors. I'd like to know how to get more information about the error. I have one generic error-handling function, and lots of different SELECTs or INSERTs that may trigger it. How can I tell which one was at fault? It is not always obvious from the error message. My code so far is... function get_rows(tx) { tx.executeSql("SELECT * FROM Blah", [], lovely_success, statement_error); } function add_row(tx) { tx.executeSql("INSERT INTO Blah (1, 2, 3)", [], carry_on, statement_error); } function statement_error(tx, error) { alert(error.code + ' / ' + error.message); } From various examples I see the error callback will be passed a transaction object and an error object. I read that .code can have the following values: UNKNOWN_ERR = 0 DATABASE_ERR = 1 VERSION_ERR = 2 TOO_LARGE_ERR = 3 QUOTA_ERR = 4 SYNTAX_ERR = 5 CONSTRAINT_ERR = 6 TIMEOUT_ERR = 7 Are there any other properties/methods of the error object? What are the properties/methods of the transaction object at this point? I can't seem to find a good online reference for this. Certainly not on the Phonegap website!

    Read the article

  • Handling nulls in Datawarehouse

    - by rrydman
    I'd like to ask your input on what the best practice is for handling null or empty data values when it pertains to data warehousing and SSIS/SSAS. I have several fact and dimension tables that contain null values in different rows. Specifics: 1) What is the best way to handle null date/times values? Should I make a 'default' row in my time or date dimensions and point SSIS to the default row when there is a null found? 2) What is the best way to handle nulls/empty values inside of dimension data. Ex: I have some rows in an 'Accounts' dimensions that have empty (not NULL) values in the Account Name column. Should I convert these empty or null values inside the column to a specific default value? 3) Similar to point 1 above - What should I do if I end up with a Facttable row that has no record in one of the dimension columns? Do I need default dimension records for each dimension in case this happens? 4) Any suggestion or tips in regards to how to handle these operation in Sql server integration services (SSIS)? Best data flow configurations or best transformation objects to use would be helpful. Thanks :-)

    Read the article

  • How to catch this low level MySQL (?) error in PHP/Magento

    - by andnil
    When I'm executing the following statement in Magento with a really large $sku, the execution terminates without any errors thrown what so ever. There are no errors in either Magento's, Apache's or PHP's error logs. Mage::getModel('catalog/product')-loadByAttribute('sku', $sku); Question: How do I catch the error? I've tried to set custom error handlers, and for testing purposes I've also managed to trigger error situations where each of the error handler functions are invoked. But when running the previously mentioned Magento code with a large $sku, none of the error handling functions are executed. error_reporting( -1 ); set_error_handler( array( 'Error', 'captureNormal' ) ); set_exception_handler( array( 'Error', 'captureException' ) ); register_shutdown_function( array( 'Error', 'captureShutdown' ) ); For completeness, this is the $sku I'm passing to loadByAttribute(). (The sku is invalid, but that is not the issue) 1- 9685 0102046|1- 9685 1212100|1- 9685 1212092|1- 9685 1212096|1- 9685 1102100|1- 9685 1102108|1- 9685 1102112|1- 9685 1102092|1- 9685 0102048|1- 9685 0102054|1- 9685 0102056|1- 9685 0102058|1- 9685 1212104|1- 9685 1212108|1- 9685 0212058|1- 9685 0104050|1- 9685 0212050|1- 9685 0212056|1- 9685 0212044|1- 9685 0212048|1- 9685 0212052|1- 9685 0212054|1- 9685 1102104|1- 9685 1102124 Any insight into this matter is much appreciated! Update: Upon further investigation, this is the exact point in the code where execution terminates. when the foreach is executed I guess Magento goes into MySQL world and starts loading up data from the database. \Mage\Catalog\Model\Abstract.php public function loadByAttribute($attribute, $value, $additionalAttributes = '*') { $collection = $this->getResourceCollection() ->addAttributeToSelect($additionalAttributes) ->addAttributeToFilter($attribute, $value) ->setPage(1,1); foreach ($collection as $object) { // <--------------- HERE return $object; } return false; } Note, I'm ONLY interested in finding out how to properly CATCH these kinds of errors, not "fix" the logic. This is so that I can present a proper error message to the user. The example above with the malformed sku is contrived and I have no desire to make my Magento app work with those erroneous skus.

    Read the article

  • Handling return value from Web Service Call Wrapper

    - by coffeeaddict
    I created this method below which makes an HTTP call to a 3rd party API. I just want opinions on if I'm handling this the best way. If the call fails, I need to return the ExistsInList bool value only if the response is not null. But in the last return statement, wouldn't I have to essentially do another return selectResponse == null ? false : selectResponse.ExistsInList; to check for null first just like the previous return in the catch? Just seems redundant the way I'm approaching this and I don't know if I really need to check for null again in the final return but I figure yes, because you can't always rely on the response to give you a valid response even if there were no errors picked up. public static bool UserExistsInList(string email, string listID) { SelectRecipientRequest selectRequest = new SelectRecipientRequest(email, listID); SelectRecipientResponse selectResponse = null; try { selectResponse = (SelectRecipientResponse)selectRequest.SendRequest(); } catch (Exception) { return selectResponse == null ? false : selectResponse.ExistsInList; } return selectResponse.ExistsInList; }

    Read the article

  • Is re-throwing an exception legal in a nested 'try'?

    - by Alexander Gessler
    Is the following well-defined in C++, or not? I am forced to 'convert' exceptions to return codes (the API in question is used by many C users, so I need to make sure all C++ exceptions are caught & handled before control is returned to the caller). enum ErrorCode {…}; ErrorCode dispatcher() { try { throw; } catch (std::bad_alloc&) { return ErrorCode_OutOfMemory; } catch (std::logic_error&) { return ErrorCode_LogicError; } catch (myownstdexcderivedclass&) { return ErrorCode_42; } catch(...) { return ErrorCode_UnknownWeWillAllDie; } } ErrorCode apifunc() { try { // foo() might throw anything foo(); } catch(...) { // dispatcher rethrows the exception and does fine-grained handling return dispatcher(); } return ErrorCode_Fine; } ErrorCode apifunc2() { try { // bar() might throw anything bar(); } catch(...) { return dispatcher(); } return ErrorCode_Fine; } I hope the sample shows my intention. My guess is that this is undefined behaviour, but I'm not sure. Please provide quotes from the standard, if applicable. Alternative approaches are appreciated as well. Thanks!

    Read the article

  • OpenGL multiple threads, variable handling [closed]

    - by toeplitz
    I have written an OpenGL program which runs in the following way: Main: - Initialize SDL - Create thread which has the OpenGL context: - Renderloop - Set camera (view) matrix with glUniform. - glDrawElements() .... etc. - Swapbuffers(); - Main SDL loop handling input events and such. - Update camera matrix of type glm::mat4. This is how I pass my camera object to the class that handles opengl. Camera *cam = new Camera(); gl.setCam(cam); where void setCam(Camera *camera) { this->camera = camera; } For rendering in the opengl context thread, this happens: glm::mat4 modelView = camera->view * model; glUniformMatrix4fv(shader->bindUniform("modelView"), 1, GL_FALSE, glm::value_ptr(modelView)); In the main program where my SDL and other things are handles I then recompute the view matrix. This his working fine without me using any mutex locks. Is this correct? On the other hand, I add objects to my scene by an "upload queue" and in this case I have to mutex lock my upload queue vector (vector class type) when adding items to it or else the program crashes. In summary: I recompute my matrix in a different thread and then use it in the opengl thread without any mutex lock. Why is this working? Edit: I think my question is similar to what was asked here: Should I lock a variable in one thread if I only need it's value in other threads, and why does it work if I don't?, only in my case it is even more simple with only one matrix being changed.

    Read the article

  • Facebook event creation through iPhone app and Facebook Connect

    - by miorel
    How is this done? Is it even possible? All the function calls seem correct, but the result is always false: NSString *event = @"{\"name\":\"A party\",\"start_time\":\"1215929160\",\"end_time\":\"1215929160\",\"location\":\"Somewhere\"}"; NSDictionary *params = [NSDictionary dictionaryWithObject:event forKey:@"event_info"]; [[FBRequest requestWithDelegate:self] call:@"facebook.events.create" params:params];

    Read the article

  • Raise event to another control with jquery

    - by Chad
    Is it possible to raise a keyup event from one control (text input) to another control (say, a select element)? In short, when certain keys are pressed in the text box (up, down, etc) I need that event to also happen in the select element.

    Read the article

  • Excel workbook event order and usage when closing Excel

    - by mas_oz2k1
    Given the following workbook events: BeforeClose BeforeSave Please tell me: - The firing order in the case of multiple workbooks alreay opened (wb1, wb2 and wb3 are opened in this order) and the user closes Excel. You can assume all 3 needs saving. - What happen if user cancels one of the saving operations say wb2? Note: Please provide link or sample .net code of event usage. ( I have the msdn event definition links already no need to post t them again)

    Read the article

  • Handle Silverlight 4 RichTextBox Paste event

    - by iulianchira
    How can I handle the Paste event for a RichTextBox control in Silverlight 4? (I want to be able to copy-paste images - the Clipboard in SL4 supports only text, so I'm sending the ImageSource Uri, and on the Paste event I want to load the image in the RichTextBox instead of the Uri string).

    Read the article

  • Java CORBA Client Disconnects When Event Fires

    - by Benny
    I have built a Java CORBA application that subscribes to an event server. The application narrows and logs on just fine, but as soon as an event is sent to the client, it breaks with the error below. Please advise. 2010/04/25!13.00.00!E00555!enserver!EventServiceIF_i.cpp!655!PID(7390)!enserver - e._info=system exception, ID 'IDL:omg.org/CORBA/TRANSIENT:1.0' TAO exception, minor code = 54410093 (invocation connect failed; ECONNRESET), completed = NO

    Read the article

  • ASP.NET panel DefaultButton event fires only once?

    - by Ahmed
    For a panel with one textbox and one button which is its default button, the DefaultButton event fires only once as editing textbox details again and pressing enter, event doesn't fire. <asp:Panel runat="server" ID="pnlNewFolderDetails" DefaultButton="btnAddFolder"> <asp:Label runat="server" ID="lblFolderHeader" Text="New Folder Name" CssClass="label" /> <asp:TextBox runat="server" ID="txtFolderName" ToolTip="Folder Name" /> <asp:Button runat="server" ID="btnAddFolder" OnClick="btnAddFolder_Click" Text="Add" /> Any suggestions?

    Read the article

  • There is no DoubleClick event for ListView control in .NET CF 3.5

    - by nmcy
    In my project, tree is a list of customers displayed in an ListView control, When user double clicks (or taps) on an item I should show the details of that customer, But there is no double click (or click event, mouse up and down events etc.) event in .NET CF 3.5 ListView control (we only have ItemActive and SelectedIndexChanged events) Is there anyone has figure out this problem?

    Read the article

  • Implementing custom CanExecuteChanged event with Commands in WPF

    - by ajtp
    Hi everybody, I try to do a custom CanExecuteChanged event for a command button. Inside CanExecuteChanged event I would like to do some stuff when canExecute value change but I don't want to do it by implementing a custom command button class (deriving from Button and Implementing ICommandSource). Also I don't want to do my stuff into CanExecute method. Any ideas? Thanks.

    Read the article

  • jQuery fullcalendar custom event

    - by raulriera
    Hi, I was wondering how to apply a custom render to a event... I want to be able to preppend the "patient" name of a practice agenda... eventRender: function(event, element) { console.log(element[0]); } This currently shows the HTML output in the console, but I don't know how can I access it (in a pretty jquery manner) in order to manipulate the data within. Thanks

    Read the article

  • jqGrid dynamic event

    - by Daveo
    Suppose I have the following (shortened for simplicity): jQuery("#grid").jqGrid({ ... ondblClickRow: function() { // I want to define this function dynamically at run time } ... }); How to I bind ondblClickRow event outside of the grid Deceleration. For example in jQuery I would normally do $('#grid').bind('ondblClickRow', function() { alert('my over written event'); });

    Read the article

< Previous Page | 66 67 68 69 70 71 72 73 74 75 76 77  | Next Page >