How to: Handle Errors in IVSS
The following section explains how to handle errors in Visual SourceSafe automation model.
Handle errors using C# application
To handle errors do the following:
Create a C# console application.
Opening of the file that does not exist causes an exception of the COMException type to be thrown. This type contains ErrorCode property. The value of this property corresponds to one of the numeric values indicating a SourceSafe Automation error.
using System; using Microsoft.VisualStudio.SourceSafe.Interop; public class TestClass { private const short ESS_VS_NOT_FOUND = -10609; public static void Main(string[] args) { VSSDatabase db = new VSSDatabase(); db.Open(@"\testdb\srcsafe.ini", Environment.UserName, ""); try { VSSItem item = db.get_VSSItem("$/bogusfile.txt", false); } catch(COMException e1) { switch((short)e1.ErrorCode) { case ESS_VS_NOT_FOUND: Console.WriteLine("file not found error"); break; default: Console.WriteLine("unrecognized COM error"); break; } } catch(Exception e2) { Console.WriteLine("unrecognized exception"); } } }
See Also
Tasks
How to: Create a C# Test Project