TryCatch does not catch exception

Hi, I am new to UiPath and I’m trying to use try catch activity. The exception cannot be caught in catch block but the system exception message box pop out. I have chose the system.exception and ran in nromal mode (which is not debug mode). How to solve this?

The error message:
System.IO.IOException: The process cannot access the file ‘trycatch.xlsx’ because it is being used by another process. at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy…ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.Packaging.ZipPackage…ctor(String path, FileMode packageFileMode, FileAccess packageFileAccess, FileShare share)
at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare)
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(String path, Boolean readWriteMode)
at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(String path, Boolean isEditable, OpenSettings openSettings)
at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(String path, Boolean isEditable)
at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName) in C:\projects\closedxml\ClosedXML\Excel\XLWorkbook_Load.cs:line 42
at ClosedXML.Excel.XLWorkbook.Load(String file) in C:\projects\closedxml\ClosedXML\Excel\XLWorkbook_Load.cs:line 32
at ClosedXML.Excel.XLWorkbook…ctor(String file, XLEventTracking eventTracking) in C:\projects\closedxml\ClosedXML\Excel\XLWorkbook.cs:line 717
at ClosedXML.Excel.XLWorkbook…ctor(String file) in C:\projects\closedxml\ClosedXML\Excel\XLWorkbook.cs:line 707
at UiPath.Excel.WorkbookFile.InitializeExistingWorbookFile()
at UiPath.Excel.WorkbookFile…ctor(String workbookPath, String password, Boolean createNew)
at UiPath.Excel.Activities.WorkbookActivity1.ConstructWorkbook(String path, String password, Boolean createNew) at UiPath.Excel.Activities.WorkbookActivity1.BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, Object state)
at System.Activities.AsyncCodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)


Here is the system message I got.

Hi @JoyceP

Welcome to Community!!

Excel is opened in background so please close that and Rerun the bot.

Cheers!!

Thank you for your responses, but I am trying to test the try catch activity so I open the excel intentionally to see whether it can catch the exception, but it seems cannot catch it

Hi,

Did you run as debug mode?
If so, for now, can you try to turn on ExecutionTrail then run debug? And check if the message is thrown by this activity?

Regards,

I tried your suggestion and it does said that the exception is come from “Read Range Workbook” Activity inside try block.

Hi,

Do you use GlobalExceptionHandler? If so, it handles exception before TryCatch.
To avoid this, can you try to remove GlobalHandler?

Regards,

No I did no use GlobalHandler :face_with_spiral_eyes: All I got is a flowchart and then the try catch activity

Hi,

If possible, can you share your project as file? It’s no problem to remove sensitive data/logic.

Regards,

UiPath trycatch.zip (9.7 KB)
Here is the project

HI,

How did you create this project?
There is information for GlobalHandler in project.json as the following.

Can you try the following step to solve this matter?

  1. Close Studio
  2. Open project.json using text editor(notepad++ etc)
  3. remove the line which has exceptionHandlerWorkflow, then save.
  4. reopen this project then run

Regards,

It works, thank you so much. I did create the project but I remember I didn’t use GlobalExceptionHandler :joy: so that’s pretty weird.

Hi,

FYI, probably this project is from StudioX task which GlobalHandeler is enabled as default in it.
If we want to remove Globalhander from the project, it’s necessary to handle it from Studio.
If just delete the GlobalHandler.xaml from file system, information for GlobalHandler remains in project.json and cause this matter.

Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.