Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libmtime
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
icon-libraries
libmtime
Commits
4492ac67
Commit
4492ac67
authored
8 years ago
by
Florian Prill
Browse files
Options
Downloads
Patches
Plain Diff
error handling example: cosmetics.
parent
0bca6c3b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/example_hl.f90
+2
-2
2 additions, 2 deletions
examples/example_hl.f90
src/error_handling.f90
+13
-4
13 additions, 4 deletions
src/error_handling.f90
with
15 additions
and
6 deletions
examples/example_hl.f90
+
2
−
2
View file @
4492ac67
...
...
@@ -97,10 +97,10 @@ PROGRAM example
test_result
=
division
(
test_number1
,
test_number2
,
ifail
)
SELECT
TYPE
(
info
=>
ifail
%
info
)
CLASS
is
(
t_arithmetic_error
)
TYPE
is
(
t_arithmetic_error
)
WRITE
(
0
,
*
)
"I'm too stupid!"
CALL
ifail
%
report
()
CLASS
is
(
t_invalid_input_error
)
TYPE
is
(
t_invalid_input_error
)
WRITE
(
0
,
*
)
"You are too stupid!"
CALL
ifail
%
report
()
CLASS
default
...
...
This diff is collapsed.
Click to expand it.
src/error_handling.f90
+
13
−
4
View file @
4492ac67
...
...
@@ -32,7 +32,6 @@ MODULE error_handling
CHARACTER
(
LEN
=
MAX_ERROR_STR_LEN
)
::
error_string
END
TYPE
t_error_info
!> Error info type: Invalid user input
TYPE
,
EXTENDS
(
t_error_info
)
::
t_invalid_input_error
END
TYPE
t_invalid_input_error
...
...
@@ -41,7 +40,6 @@ MODULE error_handling
TYPE
,
EXTENDS
(
t_error_info
)
::
t_arithmetic_error
END
TYPE
t_arithmetic_error
!> Base class for errors
TYPE
t_error
...
...
@@ -60,7 +58,11 @@ CONTAINS
SUBROUTINE
create_error
(
new_error
,
new_info
)
TYPE
(
t_error
),
INTENT
(
INOUT
)
::
new_error
CLASS
(
t_error_info
),
INTENT
(
IN
)
::
new_info
ALLOCATE
(
new_error
%
info
,
source
=
new_info
)
INTEGER
::
ierrstat
ALLOCATE
(
new_error
%
info
,
source
=
new_info
,
STAT
=
ierrstat
)
IF
(
ierrstat
/
=
0
)
THEN
WRITE
(
0
,
*
)
"error_discard: DEALLOCATE failed!"
END
IF
END
SUBROUTINE
create_error
...
...
@@ -72,6 +74,7 @@ CONTAINS
SUBROUTINE
transfer_error
(
inform
,
new_error
)
TYPE
(
t_error
),
INTENT
(
IN
)
::
inform
TYPE
(
t_error
),
INTENT
(
INOUT
)
::
new_error
IF
(
ASSOCIATED
(
new_error
%
info
))
CALL
new_error
%
report
()
new_error
%
info
=>
inform
%
info
END
SUBROUTINE
transfer_error
...
...
@@ -94,7 +97,13 @@ CONTAINS
!
SUBROUTINE
error_discard
(
this
)
CLASS
(
t_error
)
::
this
IF
(
ASSOCIATED
(
this
%
info
))
DEALLOCATE
(
this
%
info
)
INTEGER
::
ierrstat
IF
(
ASSOCIATED
(
this
%
info
))
THEN
DEALLOCATE
(
this
%
info
,
STAT
=
ierrstat
)
IF
(
ierrstat
/
=
0
)
THEN
WRITE
(
0
,
*
)
"error_discard: DEALLOCATE failed!"
END
IF
END
IF
END
SUBROUTINE
error_discard
END
MODULE
error_handling
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment