from pyasn1.codec.ber import decoder

def decodeMessageVersion(wholeMsg):
    seq, wholeMsg = decoder.decode(wholeMsg, recursiveFlag=0)
    ver, wholeMsg = decoder.decode(wholeMsg, recursiveFlag=0)
    return ver

@@ -29,16 +29,98 @@
  decoder
+%0Afrom pyasn1.error import PyAsn1Error%0Afrom pysnmp.proto.error import ProtocolError
 %0A%0Adef de
@@ -149,16 +149,29 @@
 leMsg):%0A
+    try:%0A    
     seq,
@@ -228,16 +228,20 @@
 =0)%0A    
+   
+ 
 ver, who
@@ -286,24 +286,28 @@
 siveFlag=0)%0A
+    
     return v
@@ -309,8 +309,101 @@
 urn ver%0A
+    except PyAsn1Error:%0A        raise ProtocolError('Invalid BER at SNMP version component')%0A

replace pyasn1 exceptions with pysnmp one