Search Results

Search found 13011 results on 521 pages for 'catch block'.

Page 6/521 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • Should try...catch go inside or outside a loop?

    - by mmyers
    I have a loop that looks something like this: for(int i = 0; i < max; i++) { String myString = ...; float myNum = Float.parseFloat(myString); myFloats[i] = myNum; } This is the main content of a method whose sole purpose is to return the array of floats. I want this method to return null if there is an error, so I put the loop inside a try...catch block, like this: try { for(int i = 0; i < max; i++) { String myString = ...; float myNum = Float.parseFloat(myString); myFloats[i] = myNum; } } catch (NumberFormatException ex) { return null; } But then I also thought of putting the try...catch block inside the loop, like this: for(int i = 0; i < max; i++) { String myString = ...; try { float myNum = Float.parseFloat(myString); } catch (NumberFormatException ex) { return null; } myFloats[i] = myNum; } So my question is: is there any reason, performance or otherwise, to prefer one over the other? EDIT: The consensus seems to be that it is cleaner to put the loop inside the try/catch, possibly inside its own method. However, there is still debate on which is faster. Can someone test this and come back with a unified answer? (EDIT: did it myself, but voted up Jeffrey and Ray's answers)

    Read the article

  • Nginx Browser Caching using HTTP Headers outside server/location block

    - by Danny O'Sullivan
    I am having difficulty setting the HTTP expires headers for Nginx outside of specific server (and then location) blocks. What I want is to something like the following: location ~* \.(png|jpg|jpeg|gif|ico)$ { expires 1y; } But not have to repeat it in every single server block, because I am hosting a large number of sites. I can put it in every server block, but it's not very DRY. If I try to put that into an HTTP block or outside of all other blocks, I get "location directive is not allowed here." It seems I have to put it into a server block, and I have a different server block for every virtual host. Any help/clarification would be appreciated.

    Read the article

  • XHTML validating block level element as a link

    - by Matty F
    I need a way to make an entire DL element clickable with only one anchor tag, that validates as XHTML. As in: <a> <dl> <dt>Data term</dt> <dd>Data definition</dd> </dl> </a> This currently doesn't validate as XHTML as the anchor tag cannot contain the DL. The only way I can get it to validate is if I make two anchor tags and place them inside DT and DD. As in: <dl> <dt><a>Data term</a></dt> <dd><a>Data definition</a></dt> </dl> I'm trying to avoid this, as it would result in two href attributes requiring maintenance, introducing the possibility they could become out of sync. Suggestions?

    Read the article

  • python subprocess block

    - by MW
    Hello. I'm having a problem with the module subprocess. I'm running a script from python through: subprocess.Popen('./run_pythia.sh',shell=True).communicate() and sometimes it just blocks and it doesn't finish to execute the script. Before I was using .wait() instead of .communicate() but then because of this: http://dcreager.net/2009/08/06/subprocess-communicate-drawbacks/ I changed to .communicate(). Nevertheless the problem continues. Can anyone help me?

    Read the article

  • Block All Keyboard Input in a Linux Application (Using Qt or Mono)

    - by Evans
    Hi, I'm working on a online quiz client where we use a dedicated custom-made linux distro which contains only the quiz client software along with text editors and other utility software. When the user has started the quiz, I want to prevent him/her from minimizing the window/closing it/switching to the desktop or other windows. The quizzes can be attempted using only the mouse, so I need the keyboard to be completed disabled for the period of the quiz. How could I do this, using Qt or Mono? I'm ready to use any low-level libraries/drivers, if required. Thanks Evans

    Read the article

  • Twig templates, inheritances and block usage

    - by user846226
    I've created three templates using Twig. The first one has block A defined in it, the second one extends from the first one, but includes a third template which sets the content of block A. When loading, through the browser, the url which renders b.html.twig, the content in block A (defined by the 3th template) is not positioned block _A is defined. Example: <!-- base.html.twig --> {% block _css '' %} {% block _header '' %} {% block _content '' %} {% block _footer '' %} {% block _js '' %} <!-- layout.html.twig --> <!-- header and footer are placed in the raight zone --> {% extends ::base.html.twig %} {% block _header %} {% render "MyBundleBundle:Header:header" %} {% endblock %} {% block _footer %} {% render "MyBundleBundle:Footer:footer" %} {% endblock %} <!-- my_template.html.twig --> <!-- content is also placed in the right zone but css and js blocks in the included template are not placed where declared in base.html.twig --> {% extends MyBundleBundle::layout.html.twig %} {% block _content %} SOME_CONTENT {% include MyBundleBundle::my_included_template.html.twig %} {% endblock %} <!-- my_included_template.html.twig --> {% block _css %} <link.......................> {% endblock %} {% block _js %} <script..................> {% endblock %} MORE CONTENT BELONGING TO THE INCLUDED TEMPLATE What i expect here is, _css blocks content to appear on top of the page and _js block content at the bottom, but that's not happening. I hope you can see where i'm going wrong, thanks!

    Read the article

  • I'm confused with block in ruby, compared to smalltalk.

    - by weakish
    What does block in ruby mean? It looks similar with smalltalk, but you can't send messages to it. For example, in smalltalk: [:x | x + 3] value: 3 returns 6. But in ruby: {|x| x + 3}.call 3 will cause SyntaxError. Well, you can pass messages to lambda in ruby, though: irb(main):025:0> ->(x){x+3}.call 3 => 6 So in ruby, block is not a block, but lambda is a block? Is this true? I mean, are there any differences between ruby lambda and smalltalk block? If this is true, then what is ruby block?

    Read the article

  • Block Fortress is an Awesome Tower Defense Game

    - by Akemi Iwaya
    What do you get when you mix Minecraft, tower defense, and a first-person shooter together? Block Fortress! This awesome game combines the best aspects of three game types into one unique, action-packed romp for survival and victory. Keep in mind that the game has quite a bit going on, so we will only be able to offer a quick glimpse with our post. Also, it may take a few minutes to become familiar with how to maneuver around in the game area using various gestures on your device’s screen. From the Block Fortress homepage: It offers more than 30 different building blocks, 16 different turret blocks, and tons of additional items to build (including mining blocks, lumber blocks, storage crates, power generators, and much more). It also includes many different weapon and item upgrades for your character – all brought to bear against the relentless attacks of the Goblocks! Block Fortress currently comes with three modes of game play: Survival, Quickstart, and Sandbox. As you can see, there should be more modes available at a later date. There are many types of terrain to choose from, or if you wish you can select Random for a nice surprise. For our example we chose Snowy Hills. Time to have a look around and find a nice spot to set up our barracks… This spot looks like it will do rather nicely… Just for fun we set up a castle-style set of walls and entry point for our barracks. Now on to fun and adventure! You can see what the game looks like in action with the official launch trailer… Price: 0.99 (U.S.) Block Fortress [iTunes App Store] Block Fortress Homepage Official Block Fortress Launch Trailer [YouTube]    

    Read the article

  • Arguments for or against using Try/Catch as logical operators

    - by James P. Wright
    I just discovered some lovely code in our companies app that uses Try-Catch blocks as logical operators. Meaning, "do some code, if that throws this error, do this code, but if that throws this error do this 3rd thing instead". It uses "Finally" as the "else" statement it appears. I know that this is wrong inherently, but before I go picking a fight I was hoping for some well thought out arguments. And hey, if you have arguments FOR the use of Try-Catch in this manner, please do tell. EDIT For any who are wondering, the language is C# and the code in question is about 30+ lines and is looking for specific exceptions, it is not handling ALL exceptions.

    Read the article

  • Why is this SocketException not caught by a generic catch routine?

    - by Tarnschaf
    Our company provides a network component (DLL) for a GUI application. It uses a Timer that checks for disconnections. If it wants to reconnect, it calls: internal void timClock_TimerCallback(object state) { lock (someLock) { // ... try { DoConnect(); } catch (Exception e) { // Log e.Message omitted // Raise event with e as parameter ErrorEvent(this, new ErrorEventArgs(e)); DoDisconnect(); } // ... } } So the problem is, inside of the DoConnect() routine a SocketException is thrown (and not caught). I would assume, that the catch (Exception e) should catch ALL exceptions but somehow the SocketException was not caught and shows up to the GUI application. protected void DoConnect() { // client = new TcpClient(); client.NoDelay = true; // In the following call the SocketException is thrown client.Connect(endPoint.Address.ToString(), endPoint.Port); // ... (login stuff) } The doc confirmed that SocketException extends Exception. The stacktrace that showed up is: TcpClient.Connect() -> DoConnect() -> timClock_TimerCallback So the exception is not thrown outside the try/catch block. Any ideas why it doesn't work?

    Read the article

  • When encrypting data that is not an even multiple of the block size do I have to send a complete las

    - by WilliamKF
    If I am using a block cipher such as AES which has a block size of 128 bits, what do I do if my data is not an even multiple of 128 bits? I am working with packets of data and do not want to change the size of my packet when encrypting it, yet my data is not an even multiple of 128? Does the AES block cipher allow handling of a final block that is short without changing the size of my message once encrypted?

    Read the article

  • Unhandled exception, even after adding try-catch block ? C++

    - by user2525503
    try { bool numericname=false; std::cout <<"\n\nEnter the Name of Customer: "; std::getline(cin,Name); std::cout<<"\nEnter the Number of Customer: "; std::cin>>Number; std::string::iterator i=Name.begin(); while(i!=Name.end()) { if(isdigit(*i)) { numericname=true; } i++; } if(numericname) { throw "Name cannot be numeric."; } } catch(string message) { cout<<"\nError Found: "<< message <<"\n\n"; } Why am I getting unhandled exception error ? Even after I have added the catch block to catch thrown string messages?

    Read the article

  • How to configure catch-all in Exchange2010 hub-transport environment?

    - by Itay Levin
    Im getting the delivery failed from the post master reply. i don't want it. because then poeple can find out all my real users on the exchange. also, i have a lot of users (10K) in my application - and i don't want to create a mailbox for each user. is it possible to get this done in ex2010 sp1. hub-transport configuration? or i must use edge-transport as indicated in http://technet.microsoft.com/en-us/library/bb691132(EXCHG.80).aspx

    Read the article

  • Quadcopters Play Catch [Video]

    - by Jason Fitzpatrick
    Working like a group of hive-minded bees, these quadcopters come off as almost playful with their ball throwing antics. Courtesy of the folks at the Swiss Federal Institute of Technology in Zurich’s Institute for Dynamic Systems and Control, we’re treated to a video of three quadcopters playing catch in the research facility’s Flying Machine Area. They explain the processes demonstrated in the video: This video shows three quadrocopters cooperatively tossing and catching a ball with the aid of an elastic net. To toss the ball, the quadrocopters accelerate rapidly outward to stretch the net tight between them and launch the ball up. Notice in the video that the quadrocopters are then pulled forcefully inward by the tension in the elastic net, and must rapidly stabilize in order to avoid a collision. Once recovered, the quadrotors cooperatively position the net below the ball in order to catch it. Because they are coupled to each other by the net, the quadrocopters experience complex forces that push the vehicles to the limits of their dynamic capabilities. To exploit the full potential of the vehicles under these circumstances requires several novel algorithms, including: HTG Explains: How Antivirus Software Works HTG Explains: Why Deleted Files Can Be Recovered and How You Can Prevent It HTG Explains: What Are the Sys Rq, Scroll Lock, and Pause/Break Keys on My Keyboard?

    Read the article

  • why does Visual Studio not enforce try-catch-block implementation?

    - by Pedro
    Coming from Eclipse/Java, I noticed that in VisualStudio/C# it is not mandatory to care about Exceptions. While Eclipse forces the user to implement a try-catch-block or to add a throws declaration, this is not the case in Visual Studio. What is the reason Visual Studio doesn't inform about unhandled exceptions? Can I configure Visual Studio to force me to implement try-catch-blocks, or at least add a compiler-warning?

    Read the article

  • How To Block Web Sites at the Router Level for Network Wide Filtering

    - by Jason Fitzpatrick
    A comprehensive network filtering system is overkill if all you want to do is block a handful of web sites. Read on as we show you how—with nothing more than your router—you can selectively block and temporarily restrict individual websites. For many people a massive commercial internet filter is overkill. What if you just want to block Facebook when your kids are supposed to be doing their homework or Reddit when you’re supposed to be getting work done? You don’t need a huge system for that, all you need is the access restrictions module in your router. Today we’re looking at how you can quickly and easily block traffic on your network using router-based access restrictions. HTG Explains: When Do You Need to Update Your Drivers? How to Make the Kindle Fire Silk Browser *Actually* Fast! Amazon’s New Kindle Fire Tablet: the How-To Geek Review

    Read the article

  • Best way to block a country by IP address?

    - by George Edison
    I have a website that needs to block a particular country based on IP address. I am more than aware that IP-based blocking is not a foolproof method for blocking visitors, but it is a necessary step in the right direction. Since I'm using PHP, what I would do is use a GeoIP database like geoplugin.net. However, I'm curious to know if there's a better way of doing this. The website is on a shared webserver (I don't have root access) and it is running Apache on centOS. I guess my question is "can an .htaccess file be configured to block by IP using an external source to lookup IP addresses."

    Read the article

  • Can you catch exceeded allocated memory error before it kills the script?

    - by kristovaher
    The thing is that I want to catch memory problems before they happen. I have a system that gets rows from database and casts the returned associative array to a variable, but I never know what the size of the database result is is or how much memory it will take once the database request is made. This means that my software can fail simply because memory is exceeded. But I want to avoid that somehow. One of the ways is to obviously make database requests that are smaller, but what if this is not possible or what if I do not know the size of data that is returned from database? Is it possible to 'catch' situations where memory use is exceeded in PHP? Something like this: $requestOk=memory_test(function(){ return doSomething(); }); if($requestOk){ // Memory seems fine // $requestOk now has the value from memory_test() function } else { // Function would have exceeded memory } I just find it problematic that my script can just die at any moment because of memory issues. From what I know, try-catch cannot be used here because it is a fatal error. Any help would be appreciated!

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >