API Support Forum
OEC API > API Support > IndexOutOfRangeException at OEC.API.Bases.ValueList`1.get_Item(Int32 index)
Author Topic: IndexOutOfRangeException at OEC.API.Bases.ValueList`1.get_Item(Int32 index)
(5 messages, Page 1 of 1)
Moderators: VPfau
CZendejas116
Posts: 51
Joined: Apr 13, 2011


Posted: Oct 25, 2011 @ 01:07 PM             Msg. 1 of 5
Hi,

I have this code:

try
{
method1(contract.DOM.BidSizes[0], contract.DOM.BidLevels[0], contract.DOM.AskSizes[0], contract.DOM.AskLevels[0], contract.DOM.LastUpdate);
}
catch(Exception e)
{
logger.Debug(e.Message + ":::" + e.StackTrace);
}


And I'm managing unhandled exceptions in Main method as follows:
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(GenericUnhandledException);


But I'm getting this exception, right in line where I call method1, instead of getting into catch block or into GenericUnhandledException method:

IndexOutOfRangeException. Index was outside the bounds of the array.
Source: API
StackTrace:
at OEC.API.Bases.ValueList`1.get_Item(Int32 index)
at MyApp.<method1>b__6() in C:\Users\MyApp\MyClass.cs:line 260
at System.Threading.Tasks.Task.Execute()
TargetSite: {T get_Item(Int32)}
DeclaringType: {Name = "ValueList`1" FullName = "OEC.API.Bases.ValueList`1"}


In a past topic (http://www.openecry.com/cfbb/index.cfm?page=topic&topicID=547), VictorV said that all exceptions into API.dll are handled, but with this, I think API.dll is not handling IndexOutOfRangeException.

Any Suggestions to handle this exception?

Regards,

Claudia Zendejas
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Oct 25, 2011 @ 02:39 PM             Msg. 2 of 5
Hi,

As I see from your code the referred condition is not satisfied: "if the origin of stack trace is inside OECAPI instance". In your code the origin of stack is System.Threading.Tasks.Task.Execute() method.

Victor Vins
Lead Software Developer
CZendejas116
Posts: 51
Joined: Apr 13, 2011


Posted: Oct 26, 2011 @ 09:30 AM             Msg. 3 of 5
Hi,

If we have this code:

using System;

namespace TestExceptionBehaviour
{
class Program
{
static void Main(string[] args)
{
Program program = new Program();
program.method1();
}
private void method1()
{
method2();
}
private void method2()
{
method3();
}
private void method3()
{
throw new Exception("Exception throwed!");
}
}
}


We obtain this stacktrace:
at TestExceptionBehaviour.Program.method3() in D:\samples\TestExceptionBehaviour\TestExceptionBehaviour\Program.cs:línea 25
at TestExceptionBehaviour.Program.method2() in D:\samples\TestExceptionBehaviour\TestExceptionBehaviour\Program.cs:línea 20
at TestExceptionBehaviour.Program.method1() in D:\samples\TestExceptionBehaviour\TestExceptionBehaviour\Program.cs:línea 15
at TestExceptionBehaviour.Program.Main(String[] args) in D:\samples\TestExceptionBehaviour\TestExceptionBehaviour\Program.cs:línea 10
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


So, first line in a stacktrace is where exception occurs. Same case for stacktrace in my initial post in this thread:

StackTrace:
at OEC.API.Bases.ValueList`1.get_Item(Int32 index)
at MyApp.<method1>b__6() in C:\Users\MyApp\MyClass.cs:line 260
at System.Threading.Tasks.Task.Execute()
...


Example in MSDN from Microsoft:
http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx#Y694

In addition, I attach a screenshot in which we can see that Visual Studio indicates that exception was originated in API.dll:



-

Claudia Zendejas
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Oct 26, 2011 @ 09:37 AM             Msg. 4 of 5
I feel you misunderstood "origination of stack trace" and "origination of exception". In my comment I mentioned that OECAPI handles exceptions, if stack trace is originated in OECAPI. For example, event handler doesn't catch exceptions. In your case, OECAPI will not catch this exception by design, this is a responsibility of custom application to handle them to figure out errors in the applications.

Victor Vins
Lead Software Developer
CZendejas116
Posts: 51
Joined: Apr 13, 2011


Posted: Oct 26, 2011 @ 10:17 AM             Msg. 5 of 5
Yes, I misunderstood your comments

Claudia Zendejas