<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[James's Programming Page — errors from  catch (Exception ex)]]></title>
	<link rel="self" href="https://swforum.seekye.com/feed/atom/topic/10094/" />
	<updated>2017-06-14T03:33:03Z</updated>
	<generator>PunBB</generator>
	<id>https://swforum.seekye.com/topic/10094/</id>
		<entry>
			<title type="html"><![CDATA[errors from  catch (Exception ex)]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/post/12959/#p12959" />
			<content type="html"><![CDATA[<p>First I could not get the examples to compile using vars.. It kept complaining about tryOpen not being a member. So I have to use read class types. Now I get this... See comments in try catch. I can use HID.dll from my command line C application with a report ID of 18 using 4 and 2 as a write.&nbsp; So I know the device is good.</p><p>&nbsp; HidDeviceLoader loader = new HidDeviceLoader();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HidDevice device = loader.GetDevices(0x16d0, 0x0d04).First();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HidStream stream;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;device.TryOpen(out stream);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var bytes = new byte[device.MaxOutputReportLength];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bytes[0] = 18;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bytes[1] = 4;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bytes[2] = 1;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int retry = 10;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (retry&gt;0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;stream.Write(bytes);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;catch (TimeoutException)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;retry--;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//retry<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;catch (Exception ex)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox.Show(&quot;Timeout waiting for API to respond: &quot; + ex.Message);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// ex.InnerException&nbsp; - The parameter is incorrect.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// ex.message&nbsp; operation failed early</p><br /><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return true;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//error out.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;finally<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;stream.Close();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;</p>]]></content>
			<author>
				<name><![CDATA[S_K_U_N_X]]></name>
				<uri>https://swforum.seekye.com/user/14193/</uri>
			</author>
			<updated>2017-06-14T03:33:03Z</updated>
			<id>https://swforum.seekye.com/post/12959/#p12959</id>
		</entry>
</feed>
