Search Results

Search found 16643 results on 666 pages for 'exception handling'.

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

  • Exception handling problem in release mode

    - by lama-power
    I have application with this code: Module Startup <STAThread()> _ Public Sub Main() Try Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) InitApp() Dim login As New LoginForm() Dim main As New MainForm() Application.Run(login) If login.DialogResult = DialogResult.OK Then ActUser = login.LoggedUser main.ShowDialog() End If DisposeApp() Catch ex As Exception ErrMsg(ex, "Error!", ErrorLogger.ErrMsgType.CriticalError) End End Try End Sub End Module in debug mode everithing is OK. But in release mode when somewhere in application exception occurs my global catch in Main method doesn`t catch exception. What is the problem please?

    Read the article

  • python generic exception handling and return arg on exception

    - by rikAtee
    I am trying to create generic exception handler - for where I can set an arg to return in case of exception, inspired from this answer. import contextlib @contextlib.contextmanager def handler(default): try: yield except Exception as e: yield default def main(): with handler(0): return 1 / 0 with handler(0): return 100 / 0 with handler(0): return 'helllo + 'cheese' But this results in RuntimeError: generator didn't stop after throw()

    Read the article

  • Throwing an exception while handling an exception

    - by FredOverflow
    If a destructor throws in C++ during stack unwinding caused by an exception, the program terminates. (That's why destructors should never throw in C++.) If a finally block is entered in Java because of an exception in the corresponding try block and that finally block throws another exception, the first exception is silently swallowed. This question crossed my mind: Could a programming language handle multiple exceptions being thrown at the same time? Would that be useful? Have you ever missed that ability? Is there a language that already supports this? Is there any experience with such an approach? Any thoughts?

    Read the article

  • Error Handling without Exceptions

    - by James
    While searching SO for approaches to error handling related to business rule validation , all I encounter are examples of structured exception handling. MSDN and many other reputable development resources are very clear that exceptions are not to be used to handle routine error cases. They are only to be used for exceptional circumstances and unexpected errors that may occur from improper use by the programmer (but not the user.) In many cases, user errors such as fields that are left blank are common, and things which our program should expect, and therefore are not exceptional and not candidates for use of exceptions. QUOTE: Remember that the use of the term exception in programming has to do with the thinking that an exception should represent an exceptional condition. Exceptional conditions, by their very nature, do not normally occur; so your code should not throw exceptions as part of its everyday operations. Do not throw exceptions to signal commonly occurring events. Consider using alternate methods to communicate to a caller the occurrence of those events and leave the exception throwing for when something truly out of the ordinary happens. For example, proper use: private void DoSomething(string requiredParameter) { if (requiredParameter == null) throw new ArgumentExpcetion("requiredParameter cannot be null"); // Remainder of method body... } Improper use: // Renames item to a name supplied by the user. Name must begin with an "F". public void RenameItem(string newName) { // Items must have names that begin with "F" if (!newName.StartsWith("F")) throw new RenameException("New name must begin with /"F/""); // Remainder of method body... } In the above case, according to best practices, it would have been better to pass the error up to the UI without involving/requiring .NET's exception handling mechanisms. Using the same example above, suppose one were to need to enforce a set of naming rules against items. What approach would be best? Having the method return a enumerated result? RenameResult.Success, RenameResult.TooShort, RenameResult.TooLong, RenameResult.InvalidCharacters, etc. Using an event in a controller class to report to the UI class? The UI calls the controller's RenameItem method, and then handles an AfterRename event that the controller raises and that has rename status as part of the event args? The controlling class directly references and calls a method from the UI class that handles the error, e.g. ReportError(string text). Something else... ? Essentially, I want to know how to perform complex validation in classes that may not be the Form class itself, and pass the errors back to the Form class for display -- but I do not want to involve exception handling where it should not be used (even though it seems much easier!) Based on responses to the question, I feel that I'll have to state the problem in terms that are more concrete: UI = User Interface, BLL = Business Logic Layer (in this case, just a different class) User enters value within UI. UI reports value to BLL. BLL performs routine validation of the value. BLL discovers rule violation. BLL returns rule violation to UI. UI recieves return from BLL and reports error to user. Since it is routine for a user to enter invalid values, exceptions should not be used. What is the right way to do this without exceptions?

    Read the article

  • Getting the innermost .NET Exception

    - by Rick Strahl
    Here's a trivial but quite useful function that I frequently need in dynamic execution of code: Finding the innermost exception when an exception occurs, because for many operations (for example Reflection invocations or Web Service calls) the top level errors returned can be rather generic. A good example - common with errors in Reflection making a method invocation - is this generic error: Exception has been thrown by the target of an invocation In the debugger it looks like this: In this case this is an AJAX callback, which dynamically executes a method (ExecuteMethod code) which in turn calls into an Amazon Web Service using the old Amazon WSE101 Web service extensions for .NET. An error occurs in the Web Service call and the innermost exception holds the useful error information which in this case points at an invalid web.config key value related to the System.Net connection APIs. The "Exception has been thrown by the target of an invocation" error is the Reflection APIs generic error message that gets fired when you execute a method dynamically and that method fails internally. The messages basically says: "Your code blew up in my face when I tried to run it!". Which of course is not very useful to tell you what actually happened. If you drill down the InnerExceptions eventually you'll get a more detailed exception that points at the original error and code that caused the exception. In the code above the actually useful exception is two innerExceptions down. In most (but not all) cases when inner exceptions are returned, it's the innermost exception that has the information that is really useful. It's of course a fairly trivial task to do this in code, but I do it so frequently that I use a small helper method for this: /// <summary> /// Returns the innermost Exception for an object /// </summary> /// <param name="ex"></param> /// <returns></returns> public static Exception GetInnerMostException(Exception ex) { Exception currentEx = ex; while (currentEx.InnerException != null) { currentEx = currentEx.InnerException; } return currentEx; } This code just loops through all the inner exceptions (if any) and assigns them to a temporary variable until there are no more inner exceptions. The end result is that you get the innermost exception returned from the original exception. It's easy to use this code then in a try/catch handler like this (from the example above) to retrieve the more important innermost exception: object result = null; string stringResult = null; try { if (parameterList != null) // use the supplied parameter list result = helper.ExecuteMethod(methodToCall,target, parameterList.ToArray(), CallbackMethodParameterType.Json,ref attr); else // grab the info out of QueryString Values or POST buffer during parameter parsing // for optimization result = helper.ExecuteMethod(methodToCall, target, null, CallbackMethodParameterType.Json, ref attr); } catch (Exception ex) { Exception activeException = DebugUtils.GetInnerMostException(ex); WriteErrorResponse(activeException.Message, ( HttpContext.Current.IsDebuggingEnabled ? ex.StackTrace : null ) ); return; } Another function that is useful to me from time to time is one that returns all inner exceptions and the original exception as an array: /// <summary> /// Returns an array of the entire exception list in reverse order /// (innermost to outermost exception) /// </summary> /// <param name="ex">The original exception to work off</param> /// <returns>Array of Exceptions from innermost to outermost</returns> public static Exception[] GetInnerExceptions(Exception ex) {     List<Exception> exceptions = new List<Exception>();     exceptions.Add(ex);       Exception currentEx = ex;     while (currentEx.InnerException != null)     {         exceptions.Add(ex);     }       // Reverse the order to the innermost is first     exceptions.Reverse();       return exceptions.ToArray(); } This function loops through all the InnerExceptions and returns them and then reverses the order of the array returning the innermost exception first. This can be useful in certain error scenarios where exceptions stack and you need to display information from more than one of the exceptions in order to create a useful error message. This is rare but certain database exceptions bury their exception info in mutliple inner exceptions and it's easier to parse through them in an array then to manually walk the exception stack. It's also useful if you need to log errors and want to see the all of the error detail from all exceptions. None of this is rocket science, but it's useful to have some helpers that make retrieval of the critical exception info trivial. Resources DebugUtils.cs utility class in the West Wind Web Toolkit© Rick Strahl, West Wind Technologies, 2005-2011Posted in CSharp  .NET  

    Read the article

  • Delphi Exception handling problem with multiple Exception handling blocks

    - by Robert Oschler
    I'm using Delphi Pro 6 on Windows XP with FastMM 4.92 and the JEDI JVCL 3.0. Given the code below, I'm having the following problem: only the first exception handling block gets a valid instance of E. The other blocks match properly with the class of the Exception being raised, but E is unassigned (nil). For example, given the current order of the exception handling blocks when I raise an E1 the block for E1 matches and E is a valid object instance. However, if I try to raise an E2, that block does match, but E is unassigned (nil). If I move the E2 catching block to the top of the ordering and raise an E1, then when the E1 block matches E is is now unassigned. With this new ordering if I raise an E2, E is properly assigned when it wasn't when the E2 block was not the first block in the ordering. Note I tried this case with a bare-bones project consisting of just a single Delphi form. Am I doing something really silly here or is something really wrong? Thanks, Robert type E1 = class(EAbort) end; E2 = class(EAbort) end; procedure TForm1.Button1Click(Sender: TObject); begin try raise E1.Create('hello'); except On E: E1 do begin OutputDebugString('E1'); end; On E: E2 do begin OutputDebugString('E2'); end; On E: Exception do begin OutputDebugString('E(all)'); end; end; // try() end;

    Read the article

  • Delph Exception handling problem with multiple Exception handling blocks

    - by Robert Oschler
    I'm using Delphi Pro 6 on Windows XP with FastMM 4.92 and the JEDI JVCL 3.0. Given the code below, I'm having the following problem: only the first exception handling block gets a valid instance of E. The other blocks match properly with the class of the Exception being raised, but E is unassigned (nil). For example, given the current order of the exception handling blocks when I raise an E1 the block for E1 matches and E is a valid object instance. However, if I try to raise an E2, that block does match, but E is unassigned (nil). If I move the E2 catching block to the top of the ordering and raise an E1, then when the E1 block matches E is is now unassigned. With this new ordering if I raise an E2, E is properly assigned when it wasn't when the E2 block was not the first block in the ordering. Note I tried this case with a bare-bones project consisting of just a single Delphi form. Am I doing something really silly here or is something really wrong? Thanks, Robert type E1 = class(EAbort) end; E2 = class(EAbort) end; procedure TForm1.Button1Click(Sender: TObject); begin try raise E1.Create('hello'); except On E: E1 do begin OutputDebugString('E1'); end; On E: E2 do begin OutputDebugString('E2'); end; On E: Exception do begin OutputDebugString('E(all)'); end; end; // try() end;

    Read the article

  • Tomcat Exception-Type Ignoring Specific Exception for More General

    - by David Marks
    For one type of exception, IOException, I want to display one page. For all other exceptions I have a default error page. In my web.xml I have things setup like this: java.io.IOException /queryException.jsp java.lang.Exception /error.jsp The problem is the error.jsp is the only page that ever shows, even if an IOException is thrown. The order the tags appear in doesn't matter; if I remove the java.lang.Exception tag though, I can get queryException to show for IOExceptions. What is the solution here? How can I keep a general error page for all exceptions EXCEPT for those with specific pages?

    Read the article

  • Resuming execution of code after exception is thrown and caught

    - by dotnetdev
    Hi, How is it possible to resume code execution after an exception is thrown? For exampel, take the following code: namespace ConsoleApplication1 { class Test { public void s() { throw new NotSupportedException(); string @class = "" ; Console.WriteLine(@class); Console.ReadLine(); } } class Program { static void Main(string[] args) { try { new Test().s(); } catch (ArgumentException x) { } catch (Exception ex) { } } } } After catching the exception when stepping through, the program will stop running. How can I still carry on execution? Thanks

    Read the article

  • Where did my Visual Studio exception assistant go?

    - by Steven
    Since a couple of weeks the Visual Studio (2008 9.0.30729.1 SP) Exception Assistant has stopt appearing while debugging using the C# IDE. Instead the old ugly and useless debug dialog comes up: To make sure, I've checked the following: "Tools / Options / Debugging / General / Enable the exception assistant" is on. "Debug / Exceptions / Common Language Runtime Exceptions / Thrown" is on. I reset my Visual Studio Settings. I googled. I checked all relevant stackoverflow questions. How can I get the Exception Assistant back? Who gives me the golden tip?

    Read the article

  • How to debug "The type initializer for 'my class' threw an exception"

    - by JFB
    I am getting the exception: The type initializer for 'my class' threw an exception. in my browser after running my web application. Since this seems to be an error message generated from the view (.aspx), there is no way I can see the stack trace or any log for the source of this error. I have read a bit around the net and one solution to debugging is to throw a TypeInitializationException and then looking at the inner exception to find out what was wrong. How can I do this when I don't know where to surround code with a try/catch ?

    Read the article

  • Strengthening code with possibly useless exception handling

    - by rdurand
    Is it a good practice to implement useless exception handling, just in case another part of the code is not coded correctly? Basic example A simple one, so I don't loose everybody :). Let's say I'm writing an app that will display a person's information (name, address, etc.), the data being extracted from a database. Let's say I'm the one coding the UI part, and someone else is writing the DB query code. Now imagine that the specifications of your app say that if the person's information is incomplete (let's say, the name is missing in the database), the person coding the query should handle this by returning "NA" for the missing field. What if the query is poorly coded and doesn't handle this case? What if the guy who wrote the query handles you an incomplete result, and when you try to display the informations, everything crashes, because your code isn't prepared to display empty stuff? This example is very basic. I believe most of you will say "it's not your problem, you're not responsible for this crash". But, it's still your part of the code which is crashing. Another example Let's say now I'm the one writing the query. The specifications don't say the same as above, but that the guy writing the "insert" query should make sure all the fields are complete when adding a person to the database to avoid inserting incomplete information. Should I protect my "select" query to make sure I give the UI guy complete informations? The questions What if the specifications don't explicitly say "this guy is the one in charge of handling this situation"? What if a third person implements another query (similar to the first one, but on another DB) and uses your UI code to display it, but doesn't handle this case in his code? Should I do what's necessary to prevent a possible crash, even if I'm not the one supposed to handle the bad case? I'm not looking for an answer like "(s)he's the one responsible for the crash", as I'm not solving a conflict here, I'd like to know, should I protect my code against situations it's not my responsibility to handle? Here, a simple "if empty do something" would suffice. In general, this question tackles redundant exception handling. I'm asking it because when I work alone on a project, I may code 2-3 times a similar exception handling in successive functions, "just in case" I did something wrong and let a bad case come through.

    Read the article

  • Fatal error: Uncaught exception 'Exception' in PHPExcel classes

    - by Chakrapani
    Can any one please let me know, why this following error has been thrown from PHPExcel classes Fatal error: Uncaught exception 'Exception' with message 'Could not close zip file /var/www/mydomain/myexcel.xlsx.' in /var/www/mydomain/Classes/PHPExcel/Writer /Excel2007.php:400 Stack trace: #0 /var/www/mydomain/myexcel.php(173): PHPExcel_Writer_Excel2007->save('/var/www/mydomain...') #1 {main} thrown in /var/www/mydomain/Classes/PHPExcel/Writer/Excel2007.php on line 400

    Read the article

  • Automatic bookkeeping for exception retries

    - by pilcrow
    Do any languages that support retry constructs in exception handling track and expose the number of times their catch/rescue (and/or try/begin) blocks have been executed in a particular run? I find myself counting (and limiting) the number of times a code block is re-executed after an exception often enough that this would be a handy language built-in.

    Read the article

  • DUMP in unhandled C++ exception

    - by Jorge Vasquez
    In MSVC, how can I make any unhandled C++ exception (std::runtime_error, for instance) crash my release-compiled program so that it generates a dump with the full stack from the exception throw location? I have installed NTSD in the AeDebug registry an can generate good dumps for things like memory access violation, so the matter here comes down to crashing the program correctly, I suppose. Thanks in advance.

    Read the article

  • Catching an exception that is nested into another exception

    - by Bernhard V
    Hi, I want to catch an exception, that is nested into another exception. I'm doing it currently this way: } catch (RemoteAccessException e) { if (e != null && e.getCause() != null && e.getCause().getCause() != null) { MyException etrp = (MyException) e.getCause().getCause(); ... } else { throw new IllegalStateException("Error at calling service 'beitragskontonrVerwalten'"); } } Is there a way to do this more efficient and elegant?

    Read the article

  • Implement Exception Handling in ASP.NET C# Project

    - by Shrewd Demon
    hi, I have an application that has many tiers. as in, i have... Presentation Layer (PL) - contains all the html My Codes Layer (CL) - has all my code Entity Layer (EL) - has all the container entities Business Logic Layer (BLL) - has the necessary business logic Data Logic Layer (DLL) - any logic against data Data Access Layer (DAL) - one that accesses data from the database Now i want to provide error handling in my DLL since it is responsible for executing statement like ExecureScalar and all.... And i am confused as to how to go about it...i mean do i catch the error in the DLL and throw it back to the BLL and from there throw it back to my code or what.... can any one please help me how do i implement a clean and easy error handling techinque help you be really appreciated. Thank you.

    Read the article

  • I am getting exception in main thread...even when i am handling the exception

    - by fari
    public KalaGame(KeyBoardPlayer player1,KeyBoardPlayer player2) { //super(0); int key=0; try { do{ System.out.println("Enter the number of stones to play with: "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); key = Integer.parseInt(br.readLine()); if(key<0 || key>10) throw new InvalidStartingStonesException(key); } while(key<0 || key>10); player1=new KeyBoardPlayer(); player2 = new KeyBoardPlayer(); this.player1=player1; this.player2=player2; state=new KalaGameState(key); } catch(IOException e) { System.out.println(e); } } when i enter an invalid number of stones i get this error Exception in thread "main" InvalidStartingStonesException: The number of starting stones must be greater than 0 and less than or equal to 10 (attempted 22) why isn't the exception handled by the throw i defined at KalaGame.<init>(KalaGame.java:27) at PlayKala.main(PlayKala.java:10)

    Read the article

  • Java Swing GUI exception - Exception in thread "AWT-EventQueue-0" java.util.NoSuchElementException:

    - by rgksugan
    I get this exception when i run my application. I dont have any idea what is going wrong here. Can someone help please. Exception in thread "AWT-EventQueue-0" java.util.NoSuchElementException: Vector Enumeration at java.util.Vector$1.nextElement(Vector.java:305) at javax.swing.plaf.basic.BasicTableHeaderUI.getPreferredSize(BasicTableHeaderUI.java:778) at javax.swing.JComponent.getPreferredSize(JComponent.java:1634) at javax.swing.ViewportLayout.preferredLayoutSize(ViewportLayout.java:78) at java.awt.Container.preferredSize(Container.java:1599) at java.awt.Container.getPreferredSize(Container.java:1584) at javax.swing.JComponent.getPreferredSize(JComponent.java:1636) at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:702) at java.awt.Container.layout(Container.java:1421) at java.awt.Container.doLayout(Container.java:1410) at java.awt.Container.validateTree(Container.java:1507) at java.awt.Container.validate(Container.java:1480) at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:669) at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:124) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEvent(EventQueue.java:597) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Read the article

  • How do I display exception errors thrown by Zend framework

    - by Ali
    Hi guys I'm working with Zend framework and just hate the fact that I seem to encounter hundreds of exception errors like if I try to reference a non existant property of an object my application just dies and crashes. However I have no idea where to see these errors or how to be able to display them on screen. I've set display errors to true and error reporting to E_ALL but when an error is thrown all I see is a blank page rendered only until a bit before where the error apparently occurred or the exception was thrown. Help please my debugging hours are dragging

    Read the article

  • Better exception for non-exhaustive patterns in case

    - by toofarsideways
    Is there a way to get GHCi to produce better exception messages when it finds at runtime that a call has produced value that does not match the function's pattern matching? It currently gives the line numbers of the function which produced the non-exhaustive pattern match which though helpful at times does require a round of debugging which at times I feel is doing the same set of things over and over. So before I tried to put together a solution I wanted to see if something else exists. An exception message that in addition to giving the line numbers shows what kind of call it attempted to make? Is this even possible?

    Read the article

  • What to log when an exception occurs?

    - by Rune
    public void EatDinner(string appetizer, string mainCourse, string dessert) { try { // Code } catch (Exception ex) { Logger.Log("Error in EatDinner", ex); return; } } When an exception occurs in a specific method, what should I be logging? I see a lot of the above in the code I work with. In these cases, I always have to talk to the person who experienced the error to find out what they were doing, step through the code, and try to reproduce the error. Is there any best practices or ways I can minimize all this extra work? Should I log the parameters in each method like this? Logger.Log("Params: " + appetizer + "," + mainCourse + "," + dessert, ex); Is there a better way to log the current environment? If I do it this way, will I need to write out all this stuff for each method I have in my application? Are there any best practices concerning scenarios like this?

    Read the article

  • Best exception handling practices or recommendations?

    - by user828584
    I think the two main problems with my programs are my code structure/organization and my error handling. I'm reading Code Complete 2, but I need something to read for working with potential problems. For example, on a website, if something can only happen if the user tampers with data via javascript, do you write for that? Also, when do you not catch errors? When you write a class that expects a string and an int as input, and they aren't a string and int, do you check for that, or do you let it bubble up to the calling method that passed incorrect parameters? I know this is a broad topic that can't be answered in a single answer here, so what I'm looking for is a book or resource that's commonly accepted as teaching proper exception handling practice.

    Read the article

  • Filter on exception text in elmah

    - by Uwe
    Is there a way to filter exceptions in elma using the exception message? Examples: "System.Web.HttpException: Request timed out." I don't want to filter out all HttpException, but only the timed-out requests. "System.Web.HttpException: Maximum request length exceeded." What I don't want to do is write own code for that. So is it possible to do this with the buildin-web.config configuration? Thank you!

    Read the article

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