You are not logged in. Please login at www.codechef.com to post your questions!

×

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

Java:
Use exception handling

try{

   // 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

try{
    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.

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

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

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!

asked 24 Jun '15, 13:43

drj_reddy's gravatar image

3★drj_reddy
186110
accept rate: 8%

edited 24 Jun '15, 17:00


but what can u do in case of C

link

answered 24 Jun '15, 16:00

steinsgate's gravatar image

2★steinsgate
1
accept rate: 0%

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

link

answered 24 Jun '15, 20:07

vinay_2003's gravatar image

1★vinay_2003
313
accept rate: 0%

nice info . Helped me a lot.

Thanks.

link

answered 17 Feb '17, 00:29

dpnkr's gravatar image

1★dpnkr
11116
accept rate: 0%

Thanks for this it helps!

link

answered 04 Mar '18, 16:46

subham301477's gravatar image

3★subham301477
1
accept rate: 0%

Java:

I generally use

try {

entire main class

} catch(Exception e){}

link

answered 06 Mar '18, 19:56

manav_44's gravatar image

2★manav_44
1
accept rate: 0%

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

link

answered 16 Oct '18, 05:49

sandy_123's gravatar image

3★sandy_123
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,302
×521
×422
×125
×56
×42
×40

question asked: 24 Jun '15, 13:43

question was seen: 8,273 times

last updated: 16 Oct '18, 05:49