This project is read-only.

Catching 'Unhandled CLR exception during evaluation:'

Jan 27, 2010 at 6:19 PM

Im not sure if this is generally true but:

I'm calling a .net method using clr. It throws an exception, which is expected. However, when i surround it with a guard clause, the guard clause is not executed. How do i catch exceptions thrown by clr???

(guard (e [else #f]) (clr-call ITradeDeskAut Login trade-desk user pass url connection)) -->throws

Unhandled CLR exception during evaluation:
CLR Exception: System.Runtime.InteropServices.COMException
System.Runtime.InteropServices.COMException (0x80004005): Login failed. Incorrect user name or password
   at FXCore.ITradeDeskAut.Login(String sUser, String sPassword, String sUrl, String sConnection)
   at eval-core(375).login(Object user, Object pass, Object g$$args$13050$1JmPkR)
   at #.ironscheme.exceptions::dynamic-wind(Object in, Object proc, Object out)
   at Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext, Boolean tryEvaluate) in C:\Seth\IronScheme\Microsoft.Scripting\Hosting\ScriptCode.cs:line 116
   at Microsoft.Scripting.ScriptCode.Run(ScriptModule module) in C:\Seth\IronScheme\Microsoft.Scripting\Hosting\ScriptCode.cs:line 129
   at IronScheme.Runtime.Builtins.<>c__DisplayClassa.<CompileCore>b__8() in C:\Seth\IronScheme\IronScheme\Runtime\Builtins.cs:line 530
   at IronScheme.Runtime.Builtins.EvalCore(CodeContext cc, Object expr) in C:\Seth\IronScheme\IronScheme\Runtime\Builtins.cs:line 571
   at #.ironscheme.exceptions::dynamic-wind(Object in, Object proc, Object out)
   at #.ironscheme.exceptions::dynamic-wind(Object in, Object proc, Object out)
   at IronScheme.Runtime.Builtins.CallWithCurrentContinuation(Object fc1) in C:\Seth\IronScheme\IronScheme\Runtime\Control.cs:line 185
   at IronScheme.Runtime.R6RS.Exceptions.WithClrExceptionHandler(Object handler, Object thunk) in C:\Seth\IronScheme\IronScheme\Runtime\R6RS\Exceptions.cs:line 53

Jan 27, 2010 at 6:28 PM


For CLR exceptions, use CLR-GUARD, same signature, but works like the CLR exception handling.

Looks like you are doing some fun stuff  :)



Jan 27, 2010 at 10:00 PM

Yep X OK, so how can i extract the components of the error message, the actual error message, backtrace, etc. Searching the files i cant find where the clr exception is defined! I actually just need the error message displayed minus the big backtrace.


Jan 28, 2010 at 5:40 AM


Here is an example to clarify:


> (import (ironscheme clr))
> (import (ironscheme unsafe))
> (clr-guard [e [e (clr-prop-get Exception Message e)]] ($throw (clr-new InvalidProgramException "Oh shit!")))
"Oh shit!"

Is that good?


Jan 28, 2010 at 1:19 PM

Perfect :)