Search Results

Search found 5259 results on 211 pages for 'interrupt handling'.

Page 27/211 | < Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >

  • Java: dangerous self-returning-recursive function by IOException?

    - by HH
    I had very errorsome Exception handling with if-clauses. An exception occurs if not found path. An exception returns the function again. The function is recursive. Safe? $ javac SubDirs.java $ java SubDirs Give me an path. . HELLO com TOASHEOU google common annotations base collect internal Give me an path. IT WON'T FIND ME, SO IT RETURNS ITSELF due to Exception caught Give me an path. $ cat SubDirs.java import java.io.*; import java.util.*; public class SubDirs { private List<File> getSubdirs(File file) throws IOException { List<File> subdirs = Arrays.asList(file.listFiles(new FileFilter() { public boolean accept(File f) { return f.isDirectory(); } })); subdirs = new ArrayList<File>(subdirs); List<File> deepSubdirs = new ArrayList<File>(); for(File subdir : subdirs) { deepSubdirs.addAll(getSubdirs(subdir)); } subdirs.addAll(deepSubdirs); return subdirs; } public static void search() { try{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s; System.out.println("Give me an path."); while ((s = in.readLine()) != null && s.length() != 0){ SubDirs dirs = new SubDirs(); List<File> subDirs = dirs.getSubdirs(new File(s)); for ( File f : subDirs ) { System.out.println(f.getName()); } System.out.println("Give me an path."); } }catch(Exception e){ // Simple but is it safe? search(); } } public static void main(String[] args) throws IOException { search(); } }

    Read the article

  • Problems when handling orientation changes

    - by nixau
    Hi all, I need to handle orientation changes in my Android application. For this purpose I decided to use OrientationEventListener convenience class. But his callback method is given somewhat strange behavior. My application starts in the portrait mode and then eventually switches to the lanscape one. I have some custom code executing in the callback onOrientationChanged method that provides some additional UI handling logic - it has a few calls to findViewById. What is strange is that when switching back from landscape to portrait mode onOrientationChanged callback is called twice, and what's even worse - the second call is dealing with bad Context - findViewById method starts returning null. These calls are made right from the MainThread @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); listener = new OrientationListener(); } @Override protected void onResume() { super.onResume(); // enabling listening listener.enable(); } @Override protected void onPause() { super.onPause(); // disabling listening listener.disable(); } I've replicated the same behavior with a dummy Activity without any logic except for one that deals with orientation hadling. I initiate orientation switch from the Android 2.2 emulator by pressing Ctrl+F11 What could be wrong? Upd: Inner class that implements OrientationEventListener private class OrientationListener extends OrientationEventListener { public OrientationL() { super(getBaseContext()); } @Override public void onOrientationChanged(int orientation) { toString(); } } }

    Read the article

  • Exception handling in biztalk 2006 R2

    - by IB
    Hello I have a Biztalk 2006 R2 project (used with ESB Guidance 1) I am calling from orchstration to a static method in c# code, this method uses a class to load a file data into xlang message body at part 0 When i pass filepath which doesnt exists the inside class catch the exception but dont throw it up (in the static method there is a catch block and in the orchstration there is the real handling of the exception) The static method is : public static XLANGMessage LoadFileIntoMessage(XLANGMessage message, string filePath,Encoding encoding) { try { IStreamFactory sf = new FileStreamFactory(filePath,encoding); message[0].LoadFrom(sf); return message; } catch (Exception ex) { throw ex; } } The Class which load the file stream is : private class FileStreamFactory : IStreamFactory { string _fname; Encoding _encoding; public FileStreamFactory(string fname,Encoding encoding) { _fname = fname; _encoding = encoding; } public Stream CreateStream() { try { StreamReader sr; sr = new StreamReader ( _fname, _encoding ); return sr.BaseStream; } catch (Exception ex) { throw ex; } } } I call the static method from the orchstration and expect to catch the exception in my orchstration after the class and the emthod gets it

    Read the article

  • Handling XMLHttpRequest to call external application

    - by Ian
    I need a simple way to use XMLHttpRequest as a way for a web client to access applications in an embedded device. I'm getting confused trying to figure out how to make something thin and light that handles the XMLHttpRequests coming to the web server and can translate those to application calls. The situation: The web client using Ajax (ExtJS specifically) needs to send and receive asynchronously to an existing embedded application. This isn't just to have a thick client/thin server, the client needs to run background checking on the application status. The application can expose a socket interface, with a known set of commands, events, and configuration values. Configuration could probably be transmitted as XML since it comes from a SQLite database. In between the client and app is a lighttpd web server running something that somehow handles the translation. This something is the problem. What I think I want: Lighttpd can use FastCGI to route all XMLHttpRequest to an external process. This process will understand HTML/XML, and translate between that and the application's language. It will have custom logic to simulate pushing notifications to the client (receive XMLHttpRequest, don't respond until the next notification is available). C/C++. I'd really like to avoid installing Java/PHP/Perl on an embedded device. So I'll need more low level understanding. How do I do this? Are there good C++ libraries for interpreting the CGI headers and HTML so that I don't have to do any syntax processing, I can just deal with the request/response contents? Are there any good references to exactly what goes on, server side, when handling the XMLHttpRequest and CGI interfaces? Is there any package that does most of this job already, or will I have to build the non-HTTP/CGI stuff from scratch? Thanks for any help! I am really having trouble learning about the server side of these technologies.

    Read the article

  • protecting COM interfaces from exceptions

    - by rmeador
    I have several dozen objects exposed through COM interfaces, each of which with many methods, totaling a few hundred methods. These interfaces expose business objects from my app to a scripting engine. I have been given the task of protecting every single one of these methods from exceptions being thrown (to catch them and return an error using COM's Error() function, which incidentally I can find no documentation on because it's impossible to google). To my understanding, this requires that I add a try/catch around the guts of each one of these methods. The catch blocks are going to be similar or identical for each and every one of these hundreds of methods, which strongly smells of a problem (massively violates the DRY principle), but I can't think of any way to avoid changing every method. As far as I can tell, these methods are invoked directly by COM, with no intervening code that I can hook into to catch the exceptions. My current best idea is to make a macro for the catch block, but that has it's own sort of code-smell. Can anyone come up with a better approach? BTW, my app's exceptions do not derive from std::exception, so if there is some way of COM automatically handling standard exceptions, it won't help. And I sadly cannot change the existing exceptions to derive from std::exception.

    Read the article

  • Use of 'this keyword' javascript in IE ?

    - by Ron
    Is there a workaround for Internet Explorer to implement the functionality offered by 'this' javascript keyword to get the dom element that triggered the event? My problem scenario is : I have a variable number of text fields in the html form, like input type="text" id="11" input type="text" id="12" .. I need to handle the "onchange" event for each text field, and the handling is dependent on the 'id' of the field that triggered the event. So far I understand that my options are: 1) attach a dedicated event handler for each text field. so if I have n fields, i have n different functions, something like: input type="text" id="11" onchange="function11();" input type="text" id="12" onchange="function12();" but the text fields are added and removed dynamically, so a better way would be to have one generic function instead. 2) use the 'this' keyword like: input type="text" id="11" onchange="functionGeneric(this);" input type="text" id="12" onchange="functionGeneric(this);" But this option does not work with Internet Explorer. Can anyone suggest a work around for getting it work in IE or some other solution that can be applied here? Thanks.

    Read the article

  • AS3 variables handling by AVM/compiler/scope

    - by jchmielewski
    I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code in Flash will throw an error: function myFunction() { var mc:MovieClip=new MovieClip(); var mc:MovieClip=new MovieClip(); } but it won`t throw an error in Flex (only warning in Editor). Why? .2. How Flash sees variables in loops? Apparently this: for (var i:int=0; i<2; i++) { var mc:MovieClip=new MovieClip(); } isn`t equal to just: var mc:MovieClip=new MovieClip(); var mc:MovieClip=new MovieClip(); because it will throw an error again as earlier in Flash, but in Flex in function not? Is Flash changing somehow my loop before compilation? .3. Where in a class in equivalent to timeline in Flash - where in class I would put code which I put normally on timeline (I assume it is not constructor because of what I have written earlier, or maybe it`s a matter of Flash/Flex compiler)?

    Read the article

  • Generic dataset handling library

    - by Pep.
    Hello, I want to build a generic Perl module for handling and analysing biomedical character separated datasets and which can, most certain, be used on any kind of datasets that contain a mixture of categorical (A,B,C,..) and continuous (1.2,3,881..) and identifier (XXX1,XXX2...). The plan is to have people initialize the module and then use some arguments to point to the data file(s), the place were the analysis reports should be placed and the structure of the data. By structure of data I mean which variable is in which place and its name/type. And this is where I need some enlightenment. I am baffled how to do this in a clean way. Obviously, having people create a simple schema file, be it XML or some other format would be the cleanest but maybe not all people enjoy doing something like this. The solutions I can think of are: Create a configuration file in XML or similar and with a prespecified format. Pass the information during initialization of the module. Use the first row of the data as headers and try to guess types (ouch) Surely there must be a "canonical" way of doing this that is also usable and efficient. Thanks p.

    Read the article

  • Weird Qt SSL issue -- error "No Error" shows up, nothing else, and if I ignore it, everything works

    - by houbysoft
    The issue is as follows : in my Qt app, I have a QWebView, which I use to load a HTTPS page. Everything worked fine on my development machine, so I'm now trying to get it to run on a test machine. I ran the app, but the page didn't load (the QWebView was blank). After much debugging, I found the problem is that an SSL error shows up, and the sslErrors() signal is fired. Here is my sslErrors() handling code: void blah::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors) { foreach(QSslError error, errors) { qDebug() << error.errorString() << endl; } reply->ignoreSslErrors(); } The only thing the above code prints is: "No error" So there's no error, but unless I call reply->ignoreSslErrors(), the page doesn't load (on the test machine, on my developer computer no error is reported). Huh? Is this a bug? Is it safe to ignore the error, if I make sure it's of the type "No error"?

    Read the article

  • 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

  • Event Dispatching, void pointer and alternatives

    - by PeeS
    i have my event dispatching / handling functionality working fine, but there is one issue that i need to resolve. Long story short, here are the details. // The event structure struct tEventMessage { // Type of the event int Type; // (void*) Allows those to be casted into per-Type objects void *pArgument1; void *pArgument2; }; I am sending events from different modules in my engine by using the above structure, which requires a pointer to an argument. All messages are queued, and then dispatched on the next ::Tick(). It works fine, untill i try to send something that doesn't exist in next ::Tick, for example: When a mouse click is being handled, it calculates the click coordinates in world space. This is being sent with a pointer to a vector representing that position, but after my program quits that method, this pointer gets invalid obviously, cause local CVector3 is destructed: CVector2 vScreenSpacePosition = vAt; CVector3 v3DPositionA = CVector3(0,0,0); CVector3 v3DPositionB = CVector3(0,0,0); // Screen space to World space calculation for depth zNear v3DPositionA = CMath::UnProject(vScreenSpacePosition, m_vScreenSize, m_Level.GetCurrentCamera()->getViewMatrix(), m_Level.GetCurrentCamera()->getProjectionMatrix(), -1.0 ); // Screen space to World space calculation for depth zFar v3DPositionB = CMath::UnProject(vScreenSpacePosition, m_vScreenSize, m_Level.GetCurrentCamera()->getViewMatrix(), m_Level.GetCurrentCamera()->getProjectionMatrix(), 1.0); // Send zFar position and ScreenSpace position to the handlers // Obviously both vectors won't be valid after this method quits.. CEventDispatcher::Get()->SendEvent(CIEventHandler::EVENT_SYSTEM_FINGER_DOWN, static_cast<void*>(&v3DPositionB), static_cast<void*>(&vScreenSpacePosition)); What i want to ask is, if there is any chance i could make my tEventMessage more 'template', so i can handle sending objects like in the above situation + use what is already implemented? Can't figure it out at the moment.. What else can be done here to allow me to pass some locally available data ? Please can somebody shed a bit of light on this please?

    Read the article

  • Is it OK to set state within Event Raising methods?

    - by Greg
    I ran across this pattern in the code of a library I'm using. It sets state within the event raising method, but only if the event is not null. protected virtual void OnMyEvent(EventArgs e) { if(MyEvent != null) { State = "Executing"; // Only sets state if MyEvent != null. MyEvent(this,e); } } Which means that the state is not set when overriding the method: protected override void OnMyEvent(EventArgs e) { base.OnMyEvent(e); Debug.Assert( State == "Executing" ); // This fails } but is only set when handling the event: foo.MyEvent += (o, args) => Debug.Assert(State == "Executing"); // This passes Setting state within the if(MyEvent != null) seems like bad form, but I've checked the Event Design Guidelines and it doesn't mention this. Do you think this code is incorrect? If so, why? (Reference to design guidelines would be helpful). Edit for Context: It's a Control, I'm trying to create subclass of it, and the state that it's setting is calling EnsureChildControls() conditionally based upon there being an event handler. I can call EnsureChildControls() myself, but I consider that something of a hack.

    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

  • 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

  • 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

  • INotifyPropertyChanged event listener within respective class not firing on client side (silverlight)

    - by Rob
    I'm trying to work out if there's a simple way to internalize the handling of a property change event on a Custom Entity as I need to perform some bubbling of the changes to a child collection within the class when the Background Property is changed via a XAML binding: public class MyClass : INotifyPropertyChanged { [Key] public int MyClassId { get; set; } [DataMember] public ObservableCollection<ChildMyClass> MyChildren { get; set; } public string _backgroundColor; [DataMember] public string BackgroundColor { get { return this._backgroundColor; } set { this._backgroundColor = value; if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs("BackgroundColor")); } } } public MyClass() { this.BackgroundColor = "#FFFFFFFF"; this.PropertyChanged += MyClass_PropertyChanged; } public event PropertyChangedEventHandler PropertyChanged; void MyClass_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { //Do something here - fires client side but not server side } } I can listen to the event by externalizing it without any problems but it's an ugly way to handle something that want to set and forget inside my class e.g.: public class SomeOtherClass { public SomeOtherClass() { MyClass mc = new MyClass(); mc.PropertyChanged += MyClass_PropertyChanged; } void MyClass_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { MyClass mc = (MyClass)sender; mc.UpdateChildren(); } }

    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

  • Another way to handle a common JQuery event handling pattern

    - by bradgonesurfing
    I have the following code for example $("a.foo").bind(function (e){ var t; if ( $(e.target).is("a") ){ t = $(e.target); }else{ t = $(e.target).parent("a"); } var data = t.attr("data-info"); }); In english. I might have a list of anchors within which there may be a number of spans. Each anchor is declared as <a class="foo" href="#" data-info="1"> <span> ... </span> <span> ... </span> </a> <a class="foo" href="#" data-info="2"> <span> ... </span> <span> ... </span> </a> ... ... I bind a handler to the click event of the anchor but the event object comes back with the anchor OR one of the spans depending on where I click. So to get my html5 "data-info" value into the callback I have to insert a bit of messy code. This is now appearing throughout my code to the point where I am guessing there might be an idiomatic JQuery way of handling this.

    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

< Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >