Crystal: Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS on inheritance

Created on 8 Feb 2017  路  2Comments  路  Source: crystal-lang/crystal

I was trying to create error that calls initialize of basic Exception (and extending it) class with one parameter.
I wanted to construct error message inside my custom exception and pass it to basic Exception class.
I got:

Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS

And execution timeout of course in browser.

Here is the code that activates this issue:

class CustomError < Exception
  def initialize(@param : String)
    initialize "You are not allowed to pass this custom param: #{@param}"
  end
end

raise CustomError.new "important_field"

Most helpful comment

@idchlife I believe the problem is that you're calling initialize itself, thus ending in a stack level too deep situation (and since is part of a exception, not able to catch it properly)

What you want to achieve is done by the usage of super keyword:

https://play.crystal-lang.org/#/r/1m7y

class CustomError < Exception
  def initialize(@param : String)
    super "You are not allowed to pass this custom param: #{@param}"
  end
end

raise CustomError.new "important_field"

Hope that helps.

All 2 comments

@idchlife I believe the problem is that you're calling initialize itself, thus ending in a stack level too deep situation (and since is part of a exception, not able to catch it properly)

What you want to achieve is done by the usage of super keyword:

https://play.crystal-lang.org/#/r/1m7y

class CustomError < Exception
  def initialize(@param : String)
    super "You are not allowed to pass this custom param: #{@param}"
  end
end

raise CustomError.new "important_field"

Hope that helps.

@luislavena Thank you! You are totally right.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xtagon picture xtagon  路  132Comments

asterite picture asterite  路  139Comments

MakeNowJust picture MakeNowJust  路  64Comments

fridgerator picture fridgerator  路  79Comments

asterite picture asterite  路  60Comments