This project has moved and is read-only. For the latest updates, please go here.

There is a question about SharpSnmpLib Exception

Topics: bug report (break and fix), feature request (I want ...), usage (how to ...)
Oct 31, 2008 at 3:29 AM
Code
=================================================
List<Variable> lv2 = new List<Variable>();

Variable serverName = new Variable(new ObjectIdentifier(ObjectIdentifier.Convert("1.3.6.1.2.1.1.5.0")));

Variable cpu = new Variable(new ObjectIdentifier(ObjectIdentifier.Convert("1.3.6.1.2.1.25.3.3.1.2.3")));

lv2.add(serverName );
lv2.add(cpu);

 IList<Variable> variable2 = Manager.Get(VersionCode.V2, new IPEndPoint(IPAddress.Parse("192.168.1.123"), 161), new OctetString("public"), lv2, 5000);
===============================================================================================================

Question
   当lv2中的一个项出错,整个Manager.Get(),variable2 都退出了,抛出异常。

这个有没有什么办法可以处理?如果发生异常,可以继续,给出空值?
Oct 31, 2008 at 2:56 PM
For latest source code, you may open GetRequestMessage.cs and navigate to line 200,

            if (response.ErrorStatus != ErrorCode.NoError)
            {
                throw SharpErrorException.Create(
                    "error in response",
                    _agent,
                    response.ErrorStatus,
                    response.ErrorIndex,
                    response.Variables[response.ErrorIndex - 1].Id);
            }

comment out these lines so no exception will be raised when error happens. I may provide a better solution in later releases but this is the only workaround right now.

-Lex

Marked as answer by lextm on 10/6/2013 at 9:13 PM
Nov 3, 2008 at 4:47 AM
Edited Nov 3, 2008 at 5:17 AM
Thank you very much !