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"
@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.
Most helpful comment
@idchlife I believe the problem is that you're calling
initializeitself, 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
superkeyword:https://play.crystal-lang.org/#/r/1m7y
Hope that helps.