我正在使用DLLImport从C#应用程序调用GhostScript库.
所以我有一些这样的代码,
[DllImport("gsdll32.dll", EntryPoint = "gsapi_init_with_args")]
private static extern int gsapi_init_with_args(IntPtr instance, int argc, IntPtr argv);
try
{
intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs);
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message, ex);
}
Run Code Online (Sandbox Code Playgroud)
我将看一下用C或C++编写的GhostScript源代码,但总的来说我想知道如果GhostScript代码抛出未处理的异常会发生什么?会不会被那里的捕获物捕获,或者它必须看起来像这样,
catch
{
// blah
}
Run Code Online (Sandbox Code Playgroud)
它不会抛出异常,您应该查看返回码。 http://pages.cs.wisc.edu/~ghost/doc/AFPL/7.04/API.htm#return_codes
C 编程的相当标准方法,错误返回非零代码,有时后面会调用第二个 API 来检索错误的更多详细信息。