Difference between revisions of "StackOverFlowException"

From Xojo Documentation

m (1 revision)
 
 
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
{{ClassBox
 +
| super=[[RuntimeException]]
 +
| platform=all
 +
| scope=global
 +
}}
 +
{{Description
 +
|text = Occurs when the calling chain becomes too long. }}
  
 +
<dynamicTable id="Properties" super="RuntimeException" class="propertyTable" title="Properties" columns="3">
 +
</dynamicTable>
  
=='''Description'''==
+
<dynamicTable id="Methods" super="RuntimeException" class="methodTable" title="Methods" columns="3">
Occurs when the calling chain becomes too long.
+
</dynamicTable>
  
 +
==Notes==
 +
A '''StackOverflowException''' occurs when the [[Stack |stack]] overflows. This happens when the calling chain gets too long. This can easily happen when your code makes a recursive call without providing a way to terminate the recursion-or the condition that terminates the recursive call takes too many calls to occur.
  
 
+
== Sample Code ==
=='''Super Class'''==
 
[[RuntimeException|RuntimeException]]
 
 
 
=='''Notes'''==
 
Not surprisingly, a '''StackOverflowException''' occurs when the stack overflows. This happens when the calling chain gets too long. This can easily happen when your code makes a recursive call without providing a way to terminate the recursion-or the condition that terminates the recursive call takes too many calls to occur.
 
 
 
 
 
 
 
=='''Examples'''==
 
 
The following method calls itself until the stack overflows:
 
The following method calls itself until the stack overflows:
{| cellpadding="8" cellspacing="0" border="1"
+
|<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Function|Function]] Square (value as [[Integer|Integer]]) as [[Integer|Integer]]<br /></div>
+
<rbcode>
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Return|Return]] Square(value)
+
Function Square (value As Integer) As Integer
<br /></div>
+
  Return Square(value)
 
+
End Function
|-
+
</rbcode>
|}
 
 
 
You can handle the function with the following simple [[Exception|Exception]] handler:
 
{| cellpadding="8" cellspacing="0" border="1"
 
|<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Function|Function]] Square (value as [[Integer|Integer]]) as [[Integer|Integer]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Return|Return]] Square(value)
 
<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Exception|Exception]] err
 
<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[If|If]] err [[IsA|IsA]] '''StackOverflowException''' then
 
<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[MsgBox|MsgBox]] "The stack has overflowed!"
 
<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">&#xA0;end if
 
<br /></div>
 
  
|-
+
You can handle the function with the following simple [[Exception]] handler:
|}
 
  
 +
<rbcode>
 +
Function Square (value As Integer) As Integer
 +
  Return Square(value)
  
=='''See Also'''==
+
Exception err
[[RuntimeException|RuntimeException]] class; [[Function|Function]], [[Raise|Raise]], [[Sub|Sub]] statements, [[Nil|Nil]] datatype; [[Exception|Exception]], [[Try|Try]] statements.
+
  If err IsA StackOverflowException Then
 +
    MessageBox("The stack has overflowed!")
 +
  End If
 +
</rbcode>
  
 +
==See Also==
 +
[[RuntimeException]] class; [[Function]], [[Raise]], [[Sub]] statements, [[Nil]] datatype; [[Exception]], [[Try]] statements.
  
[[Category:Runtime_Errors]]
+
[[Category:Errors_Runtime_Errors]]

Latest revision as of 22:57, 28 August 2019

Class (inherits from RuntimeException)

Occurs when the calling chain becomes too long.

Properties
ErrorNumber Message
Methods
Stack StackFrames

Notes

A StackOverflowException occurs when the stack overflows. This happens when the calling chain gets too long. This can easily happen when your code makes a recursive call without providing a way to terminate the recursion-or the condition that terminates the recursive call takes too many calls to occur.

Sample Code

The following method calls itself until the stack overflows:

Function Square (value As Integer) As Integer
Return Square(value)
End Function

You can handle the function with the following simple Exception handler:

Function Square (value As Integer) As Integer
Return Square(value)

Exception err
If err IsA StackOverflowException Then
MessageBox("The stack has overflowed!")
End If

See Also

RuntimeException class; Function, Raise, Sub statements, Nil datatype; Exception, Try statements.