Tutorial - How to debug an NZEC error?

There are a lot of posts with NZEC error. This post is aimed at helping to debug NZEC errors.

  1. NZEC stands for Non Zero Exit Code.
  2. Exit codes are codes return by running program to operating system upon either succesful termination(Exit code 0) or termination due to error(Non zero exit code).
  3. In languages which have exception handling like Java, Python etc we can use exception hadling using try - catch blocks.
  4. NZEC is a runtime error.
  5. It mostly occurs when negative array index is accesed or the program which we have written takes up more space than the allocated memory for our program to run.

Code samples and other useful information


Use exception handling

   // code which you think might throw exception
}catch(Exception t){
  // you got the exception. Now what??

submit your code with a try catch block and see if it is an Exception, if we get WA then we conclude that it is an exception, even now if you get an NZEC that means it not an exception it is an Error(NZEC output) then try the code sample below

   	new FIRESC().main1();
	// code which you think might throw exception
}catch(java.lang.Throwable t){
   // you got the exception. Now what??

As Throwable class is super class of all error and exception classes in Java we get it caught here by any means. Now try to find the error by replacing statement “java.lang.Throwable t” with different error classes from this link, now for which error you get a WA judgement that is the error throwing NZEC.


In python Exception class is the super class of all errors and exceptions.So use the below code sample

    #code that may throw an error
except Exception,e:

Then if we get WA then replace Exception with different Exception names till you get a WA and that is the error causing NZEC. Mostly the errors will be due to Memory access or division by zero.

**C: **

NZEC occurs mainly due to

  1. Infinite Recursion
  2. Incorrect Memory Access

Please contribute for other languages like C and C++, I think assert will help to some extent.

Happy Debugging!


but what can u do in case of C

Can you tell how to debug it in pascal?, it too have try and exception block.

nice info . Helped me a lot.


Thanks for this it helps!


I generally use


entire main class

} catch(Exception e){}


I got it because I didn’t remove the package declaration in java

1 Like

This is the link to my solution. This works perfectly in Pycharm but not here. Its showing NZEC. I’ve been trying to rectify it for a long time. Please help me out.


Helped me to identify the NZEC error in PYTHON \m/

Here in c++ I found, you must have to return 0 not any other value only zero (0) and problem solved.

1 Like

May be you are not returning 0 in main function, you must have to return 0 only 0 not any other value :+1:

Could you please explain in detail?
Which package and what did you do to resolve it?

lst = []
pos = 1

def call(value):
lhs = 2pos
rhs = (2
pos) + 1
if value == pos:
elif pos < value:
elif pos > value:

def fn(i_d, value):
if i_d == ‘i’:
if value not in lst:
print(‘Element already present’)
elif i_d == ‘d’:
if lst <= []:
print(‘Empty list’)
elif value in lst:
print(‘Please enter valid input’)

user_input = int(input())
for numbers in range(0, user_input):
first = input()
second = int(input())
fn(first, second)

Below is my code. I am getting error message as NZEC. Can you please help me out.

I also faced same issue, my code was like below and by removing “.parallel()”, it solved :slight_smile: . But Not sure why though.

int sum =Arrays.stream(r.readLine().split(" "))
							.mapToInt(Integer :: parseInt)

thank you so much for the help

Solution: 40881992 | CodeChef can someone tell me why i am getting nzec error in this code

my code is sucessfully run and producing output in online gdb but in Codechefcomplier it does’nt producce any output. ''even after using try catch

Try this for c:
convert void main() to int main()
and return 0 at the end.