Get Exception Codes from Journal file using Revit API 2021

Get Exception Codes from Journal file using Revit API 2021

n_mulconray
Advocate Advocate
686 Views
2 Replies
Message 1 of 3

Get Exception Codes from Journal file using Revit API 2021

n_mulconray
Advocate
Advocate

 

I want to use this hit and miss method to find out why a Revit model crashes.

AFAIK, I would have to search the journal for the keywords ExceptionCode=?????

//here is an example of the code I would use is this the best method or can I get the exception and its code more directly using the revit api...

 

 

string journalPath = doc.Application.RecordingJournalFilename;
List<string> JournalLines = new List<string>();

var fs = new FileStream(journalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (var sr = new StreamReader(fs))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (line.Contains("ExceptionCode=")

{

//record data after "ExceptionCode="

}

 

Also are the exception codes found in the journal file available from Autodesk on a site, otherwise i will just google each time i encounter a new error?

0 Likes
Accepted solutions (1)
687 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni
Accepted solution

Dear Nik,

 

Yes, that would work as you describe, afaict. I am not aware of any official list of the possible exception codes that may appear in the journal files. If you have a large collection of historical journal files available, you could simply search the globally for all exception codes that you have ever encountered, e.g., like this:

 

grep "ExceptionCode" journal*.txt | sort | uniq

 

All exceptions that can be thrown by the Revit API are listed in the Autodesk.Revit.Exceptions namespace.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 3

n_mulconray
Advocate
Advocate

If you don't have an IXian console in PowerShell you can use...

 

Select-String -Path "C:\Users\$Env:Username\AppData\Local\Autodesk\Revit\Autodesk Revit 2021\Journals\*.txt" -Pattern 'ExceptionCode=' |
Select-Object -ExpandProperty Line |
Sort-Object -Unique |
Out-File C:\Temp\ExceptionCodes.txt

 

though i have only tested with "Error:" in the journal file.

0 Likes