Search Results

Search found 13112 results on 525 pages for 'exception duck'.

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

  • Is there a reason Image.FromFile throws an OutOfMemoryException for an invalid image format?

    - by Arc
    I am writing code that catches this OutOfMemoryException and throws a new, more intuitive exception: /// ... /// <exception cref="FormatException">The file does not have a valid image format.</exception> public static Image OpenImage( string filename ) { try { return Image.FromFile( filename, ); } catch( OutOfMemoryException ex ) { throw new FormatException( "The file does not have a valid image format.", ex ); } } Is this code acceptable to its user, or is OutOfMemoryException intentionally being thrown for a particular reason?

    Read the article

  • Java resource closing

    - by Bob
    Hi, I'm writing an app that connect to a website and read one line from it. I do it like this: try{ URLConnection connection = new URL("www.example.com").openConnection(); BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); String response = rd.readLine(); rd.close(); }catch (Exception e) { //exception handling } Is it good? I mean, I close the BufferedReader in the last line, but I do not close the InputStreamReader. Should I create a standalone InputStreamReader from the connection.getInputStream, and a BufferedReader from the standalone InputStreamReader, than close all the two readers? I think it will be better to place the closing methods in the finally block like this: InputStreamReader isr = null; BufferedReader br = null; try{ URLConnection connection = new URL("www.example.com").openConnection(); isr = new InputStreamReader(connection.getInputStream()); br = new BufferedReader(isr); String response = br.readLine(); }catch (Exception e) { //exception handling }finally{ br.close(); isr.close(); } But it is ugly, because the closing methods can throw exception, so I have to handle or throw it. Which solution is better? Or what would be the best solution?

    Read the article

  • Exception: "Given final block not properly padded" in Linux, but it works in Windows

    - by user1685364
    My application works in windows, but fails in Linux with Given final block not properly padded exception. Configuration: JDK Version: 1.6 Windows : version 7 Linux : CentOS 5.8 64bit My code is below: import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; public class SecurityKey { private static Key key = null; private static String encode = "UTF-8"; private static String cipherKey = "DES/ECB/PKCS5Padding"; static { try { KeyGenerator generator = KeyGenerator.getInstance("DES"); String seedStr = "test"; generator.init(new SecureRandom(seedStr.getBytes())); key = generator.generateKey(); } catch(Exception e) { } } // SecurityKey.decodeKey("password") public static String decodeKey(String str) throws Exception { if(str == null) return str; Cipher cipher = null; byte[] raw = null; BASE64Decoder decoder = new BASE64Decoder(); String result = null; cipher = Cipher.getInstance(cipherKey); cipher.init(Cipher.DECRYPT_MODE, key); raw = decoder.decodeBuffer(str); byte[] stringBytes = null; stringBytes = cipher.doFinal(raw); // Exception!!!! result = new String(stringBytes, encode); return result; } } At the line: ciper.doFilnal(raw); the following exception is thrown: javax.crypto.BadPaddingException: Given final block not properly padded How can I fix this issue?

    Read the article

  • Disabling Xdebug's dumping of caught exceptions

    - by nuqqsa
    By default Xdebug will dump any exception regardless of whether it is caught or not: try { throw new Exception(); } catch (Exception $e) { } echo 'life goes on'; With XDebug enabled and the default settings this piece of code will actually output something like the following (nicely formatted): ( ! ) Exception: in /test.php on line 3 Call Stack # Time Memory Function Location 1 0.0003 52596 {main}( ) ../test.php:0 life goes on Is it possible to disable this behaviour and have it dumping only the uncaught exceptions? Thanks in advance. UPDATE: I'm about to conclude that this is a bug, since xdebug.show_exception_trace is disabled by default yet it doesn't behave as expected (using Xdebug v2.0.5 with PHP 5.2.10 on Ubuntu 9.10).

    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

  • c# finalizer throwing exception?

    - by sjhuk
    Quote from MSDN: If Finalize or an override of Finalize throws an exception, the runtime ignores the exception, terminates that Finalize method, and continues the finalization process. Yet if I have: ~Person() { throw new Exception("meh"); } then it results in a runtime exception? p.s. I know that this should never happen, however I'm just curious around this behaviour. One of our clients had an empty try catch around all of their finalizers.. it didn't even log when things went wrong or reserect the object :/

    Read the article

  • .NET: Avoidance of custom exceptions by utilising existing types, but which?

    - by Mr. Disappointment
    Consider the following code (ASP.NET/C#): private void Application_Start(object sender, EventArgs e) { if (!SetupHelper.SetUp()) { throw new ShitHitFanException(); } } I've never been too hesitant to simply roll my own exception type, basically because I have found (bad practice, or not) that mostly a reasonable descriptive type name gives us enough as developers to go by in order to know what happened and why something might have happened. Sometimes the existing .NET exception types even accommodate these needs - regardless of the message. In this particular scenario, for demonstration purposes only, the application should die a horrible, disgraceful death should SetUp not complete properly (as dictated by its return value), but I can't find an already existing exception type in .NET which would seem to suffice; though, I'm sure one will be there and I simply don't know about it. Brad Abrams posted this article that lists some of the available exception types. I say some because the article is from 2005, and, although I try to keep up to date, it's a more than plausible assumption that more have been added to future framework versions that I am still unaware of. Of course, Visual Studio gives you a nicely formatted, scrollable list of exceptions via Intellisense - but even on analysing those, I find none which would seem to suffice for this situation... ApplicationException: ...when a non-fatal application error occurs The name seems reasonable, but the error is very definitely fatal - the app is dead. ExecutionEngineException: ...when there is an internal error in the execution engine of the CLR Again, sounds reasonable, superficially; but this has a very definite purpose and to help me out here certainly isn't it. HttpApplicationException: ...when there is an error processing an HTTP request Well, we're running an ASP.NET application! But we're also just pulling at straws here. InvalidOperationException: ...when a call is invalid for the current state of an instance This isn't right but I'm adding it to the list of 'possible should you put a gun to my head, yes'. OperationCanceledException: ...upon cancellation of an operation the thread was executing Maybe I wouldn't feel so bad using this one, but I'd still be hijacking the damn thing with little right. You might even ask why on earth I would want to raise an exception here but the idea is to find out that if I were to do so then do you know of an appropriate exception for such a scenario? And basically, to what extent can we piggy-back on .NET while keeping in line with rationality?

    Read the article

  • Connection timed out exception, why?

    - by Dheeraj Kumar Aggarwal
    I am developing an application which uses embedded tomcat server 7, and deploys a web application on embedded server. My application accesses the embedded webapp through Rest APIs, but my clients are getting Connection Timed Out exceptions and port is also not blocked. I never gets this exception when I install this application on my local machine. Some points: IP address is used in the host name part (They are able to access this IP address on other port) Port is not blocked We are using Apache HttpClient library to access the URL Timeout interval seems not to be an issue. What are the possible reasons for this exception Connection Timed Out? or How can I simulate this problem on my local machine? Any pointers would be helpful.

    Read the article

  • How to catch exception in the main thread if the exception occurs in the secondary thread?

    - by Ashish Ashu
    How to catch exception in the main thread if the exception occurs in the secondary thread? The code snippet for the scenario is given below: private void button1_Click(object sender, EventArgs e) { try { Thread th1 = new Thread(new ThreadStart(Test)); th1.Start(); } catch (Exception) { } } void Test() { for (int i = 0; i < 100; i++) { Thread.Sleep(100); if (i == 2) throw new MyException(); } } }

    Read the article

  • ArrayIndexOutOfBounds exception in CoyoteAdapter.normalize()

    - by Alex
    I'm working with an application that uses Tomcat 5.0.28 for sending and receiving AS2 messages. At times, it's throwing the following exception on receiving an MDN receipt for a transmission: An exception or error occurred in the container during the request processing java.lang.ArrayIndexOutOfBoundsException: 0 at org.apache.coyote.tomcat5.CoyoteAdapter.normalize(CoyoteAdapter.java:483) at org.apache.coyote.tomcat5.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:239) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:158) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Unknown Source) I've found a report of this issue regarding v. 5.0.25 (here), with a followup note that it was resolved in 5.0.27. However, as above, the version number used in this app is 5.0.28. Any suggestions for how to find out what might be triggering this error?

    Read the article

  • drools.NET exception

    - by Lily
    Hi, I am using Drools.NET and got an exception when it is being called. The type initializer for 'org.drools.compiler.PackageBuilderConfiguration' threw an exception. InitializeComponent(); _Form = this; PackageBuilder builder = new PackageBuilder(); the exception comes a the line PackageBuilder builder = new PackageBuilder();

    Read the article

  • How to simulate OutOfMemory exception

    - by Gacek
    I need to refactor my project in order to make it immune to OutOfMemory exception. There are huge collections used in my project and by changing one parameter I can make my program to be more accurate or use less of the memory... OK, that's the background. What I would like to do is to run the routines in a loop: Run the subroutines with the default parameter. Catch the OutOfMemory exception, change the parameter and try to run it again. Do the 2nd point until parameters allow to run the subroutines without throwing the exception (usually, there will be only one change needed). Now, I would like to test it. I know, that I can throw the OutOfMemory exception on my own, but I would like to simulate some real situation. So the main question is: Is there a way of setting some kind of memory limit for my program, after reaching which the OutOfMemory exception will be thrown automatically? For example, I would like to set a limit, let's say 400MB of memory for my whole program to simulate the situation when there is such an amount of memory available in the system. Can it be done?

    Read the article

  • Exception handling in Boost.Asio

    - by Alex B
    Boost.Asio documentation suggests the following exception handling pattern: boost::asio::io_service io_service; ... for (;;) { try { io_service.run(); break; // run() exited normally } catch (my_exception& e) { // Deal with exception as appropriate. } } The problem with it is that the context of exception is lost at the point when it's handled. For example, if I have multiple socket sessions going on, I don't know which one caused the exception to be thrown. What would be a better way to handle the exceptions from asynchronous handlers without wrapping them in try/catch blocks?

    Read the article

  • Exception thrown when using WScript via COM in PHP

    - by user198729
    try { $cmd = 'php path_to_file.php args'; $WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run($cmd, 1, false); } catch( Exception $e ) { echo 'Caught exception: ', $e->getMessage(), "\n"; } It reports: Caught exception: Source: Unknown Description: Unknown Has anyone met this kind of problem ?

    Read the article

  • Calling the LWRP from the Exception Handler

    - by Sarah Haskins
    Is it possible to call out to a Provider (LWRP) from a Chef Exception Handler? I think my Provider is out of scope, but I don't know if what I am trying to do is possible? or advisable? Here is my provider code (cookbooks/config/provider/signal.rb): action :failure do Chef::Log.info("Yeah success") end Here is my exception handler code (exception_handler/handlers/exceptionHandler.rb): require 'chef/handler' config_signal "signal" do action :nothing end class Chef class Handler class LogCollector < Chef::Handler notifies :failure, resources(:config_signal => signal) end end end Also, if anyone has a good recommendation for general reading about scope in the context of Chef I'd appreciate it.

    Read the article

  • The uncatchable exception, pt 2

    - by chaiguy
    Ok I've done some testing and I've reduced the problem to something very simple: i. Create a method in a new class that throws an exception: public class Class1 { public void CallMe() { string blah = null; blah.ToLower(); } } ii. Create a MethodInfo that points to this method somewhere else: Type class1 = typeof( Class1 ); Class1 obj = new Class1(); MethodInfo method = class1.GetMethod( "CallMe" ); iii. Wrap a call to Invoke() in a try/catch block: try { method.Invoke( obj, null ); // exception is not being caught! } catch { } iv. Run the program without the debugger (works fine). v. Now run the program with the debugger. The debugger will halt the program when the exception occurs, even though it's wrapped in a catch handler that tries to ignore it. (Even if you put a breakpoint in the catch block it will halt before it reaches it!) In fact, the exception is happening when you run it without the debugger too. In a simple test project it's getting ignored at some other level, but if your app has any kind of global exception handling, it will get triggered there as well. This is causing me a real headache because it keeps triggering my app's crash-handler, not to mention the pain it is to attempt to debug.

    Read the article

  • Thoughts on try-catch blocks

    - by John Boker
    What are your thoughts on code that looks like this: public void doSomething() { try { // actual code goes here } catch (Exception ex) { throw; } } The problem I see is the actual error is not handled, just throwing the exception in a different place. I find it more difficult to debug because i don't get a line number where the actual problem is. So my question is why would this be good? ---- EDIT ---- From the answers it looks like most people are saying it's pointless to do this with no custom or specific exceptions being caught. That's what i wanted comments on, when no specific exception is being caught. I can see the point of actually doing something with a caught exception, just not the way this code is.

    Read the article

  • Which framework exceptions should every programmer know about ?

    - by Thibault Falise
    I've recently started a new project in C#, and, as I was coding some exception throw in a function, I figured out I didn't really know which exception I should use. Here are common exceptions that are often thrown in many programs : ArgumentException ArgumentNullException InvalidOperationException Are there any framework exceptions you often use in your programs ? Which exceptions should every .net programmer know about ? When do you use custom exception ?

    Read the article

  • Logging exceptions to database in NServiceBus

    - by IGoor
    If an exception occurs in my MessageHandler I want to write the exception details to my database. How do I do this? Obviously, I cant just catch the exception, write to database, and rethrow it since NSB rollbacks all changes. (IsTransactional is set to true) I tried adding logging functionality in a seperate handler, which I caledl using SendLocal if an exception occured, but this does not work: public void Handle(MessageItem message) { try { DoWork(); } catch(Exception exc) { Bus.SendLocal(new ExceptionMessage(exc.Message)); throw; } } I also tried using Log4Net with a custom appender, but this also rolled back. Configure.With() .Log4Net<DatabaseAppender>(a => a.Log = "Log") appender: public class DatabaseAppender : log4net.Appender.AppenderSkeleton { public string Log { get; set; } protected override void Append(log4net.Core.LoggingEvent loggingEvent) { if (loggingEvent.ExceptionObject != null) WriteToDatabase(loggingEvent.ExceptionObject); } } Is there anyway to log unhandled exceptions in the messagehandler when IsTransactional is true? Thanks in advance.

    Read the article

  • not output exception stack trace in EUnit

    - by hpyhacking
    I'm write a test with EUnit, but not anything exception detail output in console. exp_test() -> ?assertEqual(0, 1/0). Run this module:exp_test() in the Erlang Shell output following ** exception error: bad argument in an arithmetic expression in function exp_test:'-exp_test/0-fun-0-'/1 (src/test/eunit/xxx_test.erl, line 8) But in EUnit output following > eunit:test(xxx). > xxx_test: exp_test...*failed* ::badarith EUnit not output anything exception trace info Im trying the verbose config in eunit, but no effect. I want to output some exception detail in eunit test result. Thanks~

    Read the article

  • Communication between layers in an application

    - by Petar Minchev
    Hi guys! Let's assume we have the following method in the business layer. What's the best practice to tell the UI layer that something went wrong and give also the error message? Should the method return an empty String when it was OK, otherwise the error message, or should it throw another exception in the catch code wrapping the caught exception? If we choose the second variant then the UI should have another try,catch which is too much try,catch maybe. Here is a pseudocode for the first variant. public String updateSomething() { try { //Begin transaction here dataLayer.do1(); dataLayer.do2(); dataLayer.doN(); } catch(Exception exc) { //Rollback transaction code here return exc.message; } return ""; } Is this a good practice or should I throw another exception in the catch(then the method will be void)?

    Read the article

  • Exception in inserting data into data using JPA in netbeans

    - by sandeep
    SEVERE: Local Exception Stack: Exception [EclipseLink-7092] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.ValidationException Exception Description: Cannot add a query whose types conflict with an existing query. Query To Be Added: [ReadAllQuery(name="Voter.findAll" referenceClass=Voter jpql="SELECT v FROM Voter v")] is named: [Voter.findAll] with arguments [[]].The existing conflicting query: [ReadAllQuery(name="Voter.findAll" referenceClass=Voter jpql="SELECT v FROM Voter v")] is named: [Voter.findAll] with arguments: [[]].

    Read the article

  • How to handle all exceptions in a web java project

    - by Nick Donovan
    I am doing an web java project about an hotel reservation. I am using, sql, hibernate, java server pages. I want to know how can I redirect an incoming exception to an error.jsp file . There are a lot of java code , and a lot of jsp file. So I want to rederict every exception that I haven't handle to an error page, is there any way to do it ? An exception can come from everywhere and I can't know and handle them all ( for example an user can write to much data in an textfield, and it will generate me an sql exception for data to long) Thank you, sorry for my english.

    Read the article

  • javax.persistence.NoResultException: getSingleResult() did not retrieve any entities

    - by apple1988
    Hello, i have created a namedquery with ejb to check if the username is used. When the singleResult is null, then i get the following Exception : javax.persistence.NoResultException: getSingleResult() did not retrieve any entities But this exception is the result that i want when the username is free. ^^ Here is the code: public User getUserByUsername(String username) throws DAOException{ try{ Query q = em.createNamedQuery(User.getUserByUsername); q.setParameter("username", username); return (User) q.getSingleResult(); }catch(Exception e){ throwException(username, e); return null; } } Does anybody know what the problem is. :( I will return null andy don`t get an Exception. Thank you very much

    Read the article

  • How do I fix this Django error "Exception Type: OperationalError Exception Value: no such table?"

    - by user319045
    I've finally installed all the requirements (so i think!) of a Django project, and I'm trying to get a local install running on my Mac (OSX 10.4). I'm getting the following error: Blockquote OperationalError at / no such table: django_content_type Request Method: GET Request URL: http://127.0.0.1:8000/ Exception Type: OperationalError Exception Value: no such table: django_content_type Exception Location: /Users/Diesel/Desktop/DjangoWork/pinax-ev/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py in execute, line 170 Python Executable: /Users/Diesel/Desktop/DjangoWork/pinax-ev/bin/python Python Version: 2.5.1

    Read the article

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