Exception handling fails - Help!

16 views
Skip to first unread message

Ricardo Canelas

unread,
Mar 19, 2018, 1:58:43 PM3/19/18
to FoX-discuss
Hey all,

I'm having an issue. essentially:

! Load in the document
  myDoc => parseFile("h2o.xml", iostat=ios, ex=ex)
  if (inException(ex)) then
    print*,"DOM Parse error ", getExceptionCode(ex)
    stop
  else
    !stmg else
 endif

fails to catch the exception. If 'h2o.xml' doesn't exist a severe access violation aborts the execution. This happens across every functionality of FoX on my build, and I can't understand why.

I'm on windows, built the last github repo using cmake -> visual studio -> ifort 2017

Regards,
Ricardo


Andrew Walker [EAR]

unread,
Apr 1, 2018, 10:05:28 AM4/1/18
to fox-d...@googlegroups.com
Hi Ricardo,

Sorry about the delay in getting back to you. I don't get as much time to work on FoX as I once did.

I suspect there are a few things going on here. First, make sure that the 'ex' variable is not a pointer (that was the only way I could get a segmentation fault out of this). Second, you need to check the value of the 'ios' variable. If this optional argument is present and the file cannot be found that's the variable that gets set in the parseFIle function. If 'ios' is not present FoX will abort itself reporting that it "Cannot open file". This kind of error does not get attached the DOMException.

So, what I ended up with is:

program dom_open_errors_example


  use FoX_dom

  implicit none


  type(Node), pointer :: myDoc

  type(DOMException) :: ex

  integer :: ios


  myDoc => parseFile("h2o.xml", iostat=ios, ex=ex)

  if (ios.ne.0) then

      print*, "Problem reading file. iostat was ", ios

      stop


  elseif (inException(ex)) then

      print*,"DOM Parse error ", getExceptionCode(ex)

      stop


  else

      print*, "Not in exception and file read OK"


  endif


  ! Do something with myDoc


end program dom_open_errors_example



Hopefully this works for you. You should see a DOM Parse error if the XML file exists but is not well-formed XML, and a non-zero iostat (strictly with a machine-specific meaning) if the file cannot be read. One oddity to note is that if ex is not present but ios is, you may end up with a FoX error code in ios. That only happens if the file exists but it not well-formed XML.


I'll add an annotated version of this to the examples directory.


Best wishes,


Andrew



--
You received this message because you are subscribed to the Google Groups "FoX-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fox-discuss...@googlegroups.com.
To post to this group, send email to fox-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/fox-discuss.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages