I'm developing a program that would require huge amount of memory, and I want to catch when out-of-memory exception happens. I had heard this is not possible to do, but curious if there is any development on this end.
120763
I have to serialize around a million items and I get the following exception when I run my code:  Exception in thread "main" java.lang.OutOfMemoryError: Java heap space     at java.util.Arrays.copyOfRange(Unknown Source)     at java.lang.String.&lt;init&gt;(Unknown Source)     at java.io.BufferedReader.readLine(Unknown Source)     at java.io.BufferedReader.readLine(Unknown Source)     at org.girs.TopicParser.dump(TopicParser.java:23)     at org.girs.TopicParser.main(TopicParser.java:59)   How do I handle this?
77532
In C# code can you catch a native exception thrown from deep in some unmanaged library? If so do you need to do anything differently to catch it or does a standard try...catch get it?
68536
In several modern programming languages (including C++, Java, and C#), the language allows  to occur at runtime without raising any kind of error condition.  For example, consider this (contrived) C# method, which does not account for the possibility of overflow/underflow.  (For brevity, the method also doesn't handle the case where the specified list is a null reference.)    //Returns the sum of the values in the specified list. private static int sumList(List&lt;int&gt; list) {     int sum = 0;     foreach (int listItem in list)     {         sum += listItem;     }     return sum; }   If this method is called as follows:  List&lt;int&gt; list = new List&lt;int&gt;(); list.Add(2000000000); list.Add(2000000000); int sum = sumList(list);   An overflow will occur in the sumList() method (because the int type in C# is a 32-bit signed integer, and the sum of the values in the list exceeds the value of the maximum 32-bit signed integer). The sum variable will have a value of -294967296 (not a value of 4000000000); this most likely is not what the (hypothetical) developer of the sumList method intended.  Obviously, there are various techniques that can be used by developers to avoid the possibility of integer overflow, such as using a type like Java's , or the  keyword and  compiler switch in C#.  However, the question that I'm interested in is why these languages were designed to by default allow integer overflows to happen in the first place, instead of, for example, raising an exception when an operation is performed at runtime that would result in an overflow.  It seems like such behavior would help avoid bugs in cases where a developer neglects to account for the possibility of overflow when writing code that performs an arithmetic operation that could result in overflow.  (These languages could have included something like an "unchecked" keyword that could designate a block where integer overflow is permitted to occur without an exception being raised, in those cases where that behavior is explicitly intended by the developer; C# actually .)  Does the answer simply boil down to performance -- the language designers didn't want their respective languages to default to having "slow" arithmetic integer operations where the runtime would need to do extra work to check whether an overflow occurred, on every applicable arithmetic operation -- and this performance consideration outweighed the value of avoiding "silent" failures in the case that an inadvertent overflow occurs?  Are there other reasons for this language design decision as well, other than performance considerations?
76968
I wanted to set some handler for all the unexpected exceptions that I might not have caught inside my code. In Program.Main() I used the following code:  AppDomain.CurrentDomain.UnhandledException     += new UnhandledExceptionEventHandler(ErrorHandler.HandleException);   But it didn't work as I expected. When I started the application in debugging mode and threw an exception it did call the handler, but afterwards the exception helper in Visual Studio popped up as if the exception occurred without any handling. I tried Application.Exit() inside the handler but it didn't work as well.  What I would like to achieve is that the exception is handled with my handler and then the application closes nicely. Is there any other way to do it or am I using the code above in the wrong way?
11091
When debugging an application in Visual Studio, there are 2 options for breaking on exceptions. Break as soon as an exception is thrown, and breaking only when an exception isn't caught. This works fine when developing desktop applications. However, when developing ASP.NET applications, all exceptions are eventually caught by the code in IIS.  Is it possible to disable this behavior, so that the debugger breaks when my ASP.Net application code fails to catch an exception?  Edit: Just to be clear, I don't want to break whenever an exception is thrown, as many times they are handled just fine by my code, and I don't want to stop on every exception. I only want to stop on the exceptions that aren't handled by my code.  Edit: This seems to not be an issue in Visual Studio 2008. In Visual Studio 2003, all exceptions were treated as user handled, because the ASP.NET runtime caught all the exceptions so as not to bring down the web server process. It seems that in Visual Studio 2008, this type of exception catching is not counted when checking for user-unhandled exceptions.
68068
How can I find out the size of a file I opened with an application written in C ?  I would like to know the size, because I want to put the content of the loaded file into a string, which I allocate using malloc(). Just writing malloc(10000*sizeof(char)); is IMHO a bad idea.
117975
I've got a "Schroedinger's Cat" type of problem here -- my program (actually the test suite for my program, but a program nonetheless) is crashing, but only when built in release mode, and only when launched from the command line.  Through caveman debugging (ie, nasty printf() messages all over the place), I have determined the test method where the code is crashing, though unfortunately the actual crash seems to happen in some destructor, since the last trace messages I see are in other destructors which execute cleanly.  When I attempt to run this program inside of Visual Studio, it doesn't crash.  Same goes when launching from WinDbg.exe.  The crash only occurs when launching from the command line.  This is happening under Windows Vista, btw, and unfortunately I don't have access to an XP machine right now to test on.  It would be really nice if I could get Windows to print out a stack trace, or something other than simply terminating the program as if it had exited cleanly.  Does anyone have any advice as to how I could get some more meaningful information here and hopefully fix this bug?  Edit: The problem was indeed caused by an out-of-bounds array, .  Thanks everybody for your help in finding this problem!
114809
Short of using a profiler, is there any way inside a running program to detect first chance exceptions?  Ideally, I would like to record more detailed state information that is not available once the catch block has taken over the final exception.
14101
I have a loop going, but there is the possibility for exceptions to be raised inside the loop. This of course would stop my program all together. To prevent that I catch the exceptions and handle them. But then the rest of the iteration runs even though an exception occurred. Is there a keyword to use in my except: clause to just skip the rest of the current iteration?
95490
Why am I getting an out of memory exception?  So this dies in C# on the first time through:  splitBitmaps.Add(neededImage.Clone(rectDimensions, neededImage.PixelFormat));   Where splitBitmaps is a List&lt;BitMap&gt; BUT this works in VB for at least 4 iterations:  arlSplitBitmaps.Add(Image.Clone(rectDimensions, Image.PixelFormat))  Where arlSplitBitmaps is a simple array list.  (And yes I've tried arraylist in c#)  This is the fullsection:  for (Int32 splitIndex = 0; splitIndex &lt;= numberOfResultingImages - 1; splitIndex++) {    Rectangle rectDimensions;    if (splitIndex &lt; numberOfResultingImages - 1)    {     rectDimensions = new Rectangle(splitImageWidth * splitIndex, 0,        splitImageWidth, splitImageHeight);    }    else    {     rectDimensions = new Rectangle(splitImageWidth * splitIndex, 0,       sourceImageWidth - (splitImageWidth * splitIndex), splitImageHeight);    }     splitBitmaps.Add(neededImage.Clone(rectDimensions, neededImage.PixelFormat));    }   neededImage is a Bitmap by the way.   I can't find any useful answers on the intarweb, especially not why it works just fine in VB.  Update:  I actually found a reason (sort of) for this working but forgot to post it.  It has to do with converting the image to a bitmap instead of just trying to clone the raw image if I remember.
105282
Using C#, I want to get the total amount of RAM that my computer has. With the PerformanceCounter I can get the amount of Available ram, by setting:  counter.CategoryName = "Memory"; counter.Countername = "Available MBytes";   But I can't seem to find a way to get the total amount of memory.  How would I go about doing this?  Update:  MagicKat: I saw that when I was searching, but it doesn't work - "Are you missing an assembly or reference?". I've looked to add that to the References, but I don't see it there.
98616
I can hookup to AppDomain.CurrentDomain.UnhandledException to log exceptions from background threads, but how do I prevent them terminating the runtime?
67310
While googling, I see that using  can be slow.  has a  method that is available as well.  Is there an efficient way in java to get the file size?
56705
I'm currently building a Java app that could end up being run on many different platforms, but primarily variants of Solaris, Linux and Windows.  Has anyone been able to successfully extract information such as the current disk space used, CPU utilisation and memory used in the underlying OS? What about just what the Java app itself is consuming?  Preferrably I'd like to get this information without using JNI.
11842
I know that according to C++ standard in case the new fails to allocate memory it is supposed to throw std::bad_alloc exception. But I have heard that some compilers such as VC6 (or CRT implementation?) do not adhere to it. Is this true ? I am asking this because checking for NULL after each and every new statement makes code look very ugly.
81086
We have a few Win32 applications (coded in Delphi 2006) where sometimes the user gets an error message saying "System Error. Code: 8. Not enough storage is available to process this command.".  From the stacktrace it looks like it is always during CreateWnd call  Main ($1edc): 004146cc +070 app.exe SysUtils               RaiseLastOSError 00414655 +005 app.exe SysUtils               RaiseLastOSError 004ce44c +130 app.exe Controls               TWinControl.CreateWnd 00535a72 +022 app.exe cxControls             TcxControl.CreateWnd 004ce82a +016 app.exe Controls               TWinControl.CreateHandle 00553d21 +005 app.exe cxContainer            TcxContainer.CreateHandle 00586ef1 +005 app.exe cxEdit                 TcxCustomEdit.CreateHandle 005c331d +005 app.exe cxDropDownEdit         TcxCustomDropDownEdit.CreateHandle 004ceaf0 +074 app.exe Controls               TWinControl.UpdateShowing 004ceb1e +0a2 app.exe Controls               TWinControl.UpdateShowing 004cebdc +03c app.exe Controls               TWinControl.UpdateControlState 004d118a +026 app.exe Controls               TWinControl.CMVisibleChanged 004cb713 +2bb app.exe Controls               TControl.WndProc 004cf569 +499 app.exe Controls               TWinControl.WndProc 004b727d +4c1 app.exe Forms                  TCustomForm.WndProc 004cb3a0 +024 app.exe Controls               TControl.Perform 004c9f6a +026 app.exe Controls               TControl.SetVisible 004b6c46 +03a app.exe Forms                  TCustomForm.SetVisible 004baf1b +007 app.exe Forms                  TCustomForm.Show 004bb151 +14d app.exe Forms                  TCustomForm.ShowModal 007869c7 +0d3 app.exe UfrmPrice      770 +19 TfrmPrice.EditPrice 0078655d +009 app.exe UfrmPrice      628  +0 TfrmPrice.actNewBidExecute 00431ce7 +00f app.exe Classes                TBasicAction.Execute 004c2cb5 +031 app.exe ActnList               TContainedAction.Execute 004c397c +050 app.exe ActnList               TCustomAction.Execute 00431bb3 +013 app.exe Classes                TBasicActionLink.Execute 004af384 +090 app.exe Menus                  TMenuItem.Click 004b059f +013 app.exe Menus                  TMenu.DispatchCommand 004b16fe +082 app.exe Menus                  TPopupList.WndProc 004b164d +01d app.exe Menus                  TPopupList.MainWndProc 004329a8 +014 app.exe Classes                StdWndProc 7e4196b2 +00a USER32.dll                     DispatchMessageA 004bea60 +0fc app.exe Forms                  TApplication.ProcessMessage 004bea9a +00a app.exe Forms                  TApplication.HandleMessage 004becba +096 app.exe Forms                  TApplication.Run 008482c5 +215 app.exe AppName        129 +42 initialization   I've never been able to get to the bottom of what causes this and as it happens fairly seldom I haven't been to concerned, but I would like to find out what causes it and hopefully rectify it...  EDIT: Full Stacktrace  EDIT 2: More info... The client who experienced this today has had my app installed for about 4 months and it is running on his PC 8 hours a day. The problem only appeared today and kept reappearing even though he killed my app and restarted it. None of the other apps on his system behaved strangely. After a reboot the problem goes away completely. Does this point towards the heap shortage that Steve mentions?  EDIT 3: Interesting msdn blog post  and  on the topic of the desktop heap. Though I'm not sure whether this is the cause of the problem it certainly looks likely.
70096
I wonder how can I write a catch'em all exception handler in the application level which will give the user the option to resume the application flow?