Try and Except in EViews

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

justincn
Posts: 4
Joined: Mon Mar 11, 2024 4:20 pm

Try and Except in EViews

Postby justincn » Fri Sep 27, 2024 12:20 pm

Mac user here, but I am using Eviews through Parallels Desktop. One issue that I encounter frequently is a changing drive. For example

fetch(d="x:\<path-to-a -database\somedatabase.edb") {%CONCEPTS}

Will work sometimes, but randomly “x” will change to the “w” drive (or even sometimes "y") and I don’t know why that is. So I’m forced to just hard code it to

fetch(d="w:\<path-to-a -database\somedatabase.edb") {%CONCEPTS}

The behavior is quite inconsistent. Is it possible to execute some form a try and except?

Something along the lines of

try:
fetch(d="x:\<path-to-a -database\somedatabase.edb") {%CONCEPTS}

except:
fetch(d="w:\<path-to-a -database\somedatabase.edb") {%CONCEPTS}


Is there a way to do this in EViews?

EViews Matt
EViews Developer
Posts: 569
Joined: Thu Apr 25, 2013 7:48 pm

Re: Try and Except in EViews

Postby EViews Matt » Fri Sep 27, 2024 3:23 pm

Hello,

EViews doesn't provide exception-style error handling, but a program can detect that an error has occurred and react rather than simply stopping. For example:

Code: Select all

setmaxerrs 2 fetch(d="x:\<path-to-a -database\somedatabase.edb") {%CONCEPTS} !error_occurred = @errorcount > 0 clearerrs setmaxerrs 1 if !error_occurred then fetch(d="w:\<path-to-a -database\somedatabase.edb") {%CONCEPTS} endif
The basic idea is to increase the allowed error limit before EViews halts the program, run the statement that may generate an error, detect whether an error occurred, and then react if necessary.

justincn
Posts: 4
Joined: Mon Mar 11, 2024 4:20 pm

Re: Try and Except in EViews

Postby justincn » Mon Sep 30, 2024 8:57 am

Thanks for the response, Matt! I will try to fold this in.


Return to “Programming”

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 0 guests