I found an RuntimeError: ERROR 999998: Unexpected Error when lunching Arcpy in my ArcGis 10.1 such as this:

Runtime error 
Traceback (most recent call last):
  File "", line 50, in 
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py", line 3840, in Minus
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Utils.py", line 47, in swapper
    result = wrapper(*args, **kwargs)
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py", line 3837, in wrapper
    return _wrapLocalFunctionRaster(u"Minus_sa", ["Minus", in_raster_or_constant1, in_raster_or_constant2])
RuntimeError: ERROR 999998: Unexpected Error.

I've extensively gone through forums and found similar problems, but nothing proposed has resolved this problem. I haven't tried to reinstall ArcGIS, though.

My code is:

Also, when I execute the code, it gives OK until the Print "Ok1", which means that transmissionCapacity = Minus(tc1, losses) is not executed. Error 999998 worries me a lot.

  • Line 50 seems to be the problem from what you posted at the top, but Print "OK 1" is on line 42. And it looks like 999998 is OS related.
    – gm70560
    Commented Apr 11, 2013 at 14:31
  • Line 42 comes to be: transmissionCapacity = Minus(tc1, losses)...... I knew that that may be the problem as print "Ok1" didn't print out. But I have no clue which can be the problem on that, I'm substracting one number "tc1" to one layer affected bu the layer Distance, and that's why I use Minus.... but don't know why it comes wrong...
    – tom
    Commented Apr 11, 2013 at 15:12

2 Answers 2


You might be having a problem related to memory, which is why that error is being thrown.
Here is a help article that discusses Foreground vs Background processing. It directly references the error that you are receiving and relates it to running out of System memory.

Foreground and Background Processing

Taking a quick look at your python script, you are running 9 raster operations in your script before you reach Line 42. I am not sure whether you are running this from the Python window in ArcGIS, or if you are running it from an external IDE. I think the issue might arise regardless though. I know that in other programming I have done, the software does not empty memory out between functions. It basically keeps working in the same memory space until the entire script is completed. This could mean that each time you are running one of the Spatial Analyst functions, the raster is loaded into memory, and then kept there when it is finished and has moved on. Depending on the size of your raster, you could be filling up your entire memory allocation and the Minus function at Line 42 happens to be the one that fills up your memory mid-stream and causes the crash.

I am not enough of a python or arcpy guru to be able to say whether this is actually the case. There may be ways of forcing the memory to flush mid-script. Here are a couple of options that may help:

  • Clear your variables as you are finished with them.
  • Write some of these intermediate rasters to disk instead of keeping them in memory the entire time.
  • Split your script up into parts and run it in two or more sections. This would let you clear out the ram more often.

This Stackoverflow entry discusses freeing memory in Python: How can I explicitly free memory in Python?
Also, doing a search at the Python website is always a good idea.

Hope this helps.

  • Hi everyone! Although the answer before it's very reasonable, I have tryied everything but still not working :( Really I´ve no more idea of what to do, but when I try to do any basic calculation with a layer affected by the variable "distance", it calculates it in the first beginning but not at the end of the code when also a layer is affected. It does't apply the variable "distance" twice. Sorry :( that is very very important and I don't know what else I could do.... Thanks.
    – tom
    Commented Apr 17, 2013 at 13:24
  • Came to this four years later, and it helped tremendously. This was an issue for me when I was running an extremely memory-intensive process in ArcCatalog, and trying to run a fairly simple operation with arcpy for another task.
    – AlecZ
    Commented Jan 4, 2018 at 20:43

Errors should be analysed with Event Log Explorer to permanently get rid of the problem otherwise it keeps on reoccurring. Sometimes the previous logs should be analysed properly as they are the root cause of the real error. Check this for Windows Error log Analysis http://eventlogxp.com/blog/troubleshooting-philosophy-windows-event-log-error-analysis/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.