Skip to content

Commit a530e2e

Browse files
docs: expand MAPDL error-handling docs and add PDF download link (#4282)
* docs: expand MAPDL error-handling docs and add PDF download link - Expand "Warnings and errors" to describe Pythonic exception conversion and error-handling behavior - Add concrete try/except examples (including MapdlRuntimeError) and an example showing handling of specific Mapdl exceptions - Document the exception hierarchy and common error classes - Clarify that ignore_errors is an attribute and show usage - Add link to download the complete PyMAPDL documentation PDF in the Getting Started learning page * chore: adding changelog file 4282.documentation.md [dependabot-skip] * docs: remove duplicated pymapdl_latest_pdf_doc link from links.rst --------- Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
1 parent d9189c8 commit a530e2e

File tree

4 files changed

+71
-10
lines changed

4 files changed

+71
-10
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Expand MAPDL error-handling docs and add PDF download link

doc/source/getting_started/learning.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Downloads
4343
- View and download :download:`PyMAPDL cheatsheet <https://github.com/ansys/pymapdl/blob/gh-pages/version/{{ version }}/_static/cheat_sheet.pdf>`
4444
to help you to learn PyMAPDL.
4545

46+
- Download the complete `PyMAPDL documentation as PDF <pymapdl_latest_pdf_doc_>`_
47+
from the latest GitHub release for offline access.
48+
4649
- Visit :ref:`ref_examples` to learn how PyMAPDL can be used to solve different real problems.
4750

4851

doc/source/links.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@
190190
.. _pymapdl_conf_file: https://github.com/ansys/pymapdl/blob/main/doc/source/conf.py
191191
.. _pymapdl_search_issues_pr: https://github.com/ansys/pymapdl/issues?q=
192192
.. _pymapdl_latest_github_release: https://github.com/ansys/pymapdl/releases/latest
193-
.. _pymapdl_latest_pdf_doc: https://github.com/ansys/pymapdl/releases/download/v%%PYMAPDLVERSION%%.0/pymapdl-Documentation-%%PYMAPDLVERSION%%.0.pdf
194193
.. _pymapdl_discussion_speed_pymapdl_mapdl: https://github.com/ansys/pymapdl/discussions/757
195194
.. _pymapdl_devcontainer_configuration: https://github.com/ansys/pymapdl/blob/main/.devcontainer/devcontainer-local/devcontainer.json
196195
.. _pymapdl_build_docker_compose: https://github.com/ansys/pymapdl/tree/main/.devcontainer/docker-compose.yml

doc/source/user_guide/mapdl.rst

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,30 @@ attribute or implemented Pythonically.
504504

505505
Warnings and errors
506506
-------------------
507-
Errors are handled Pythonically. For example:
507+
508+
PyMAPDL provides comprehensive error handling that converts MAPDL warnings and errors
509+
into Python exceptions. This approach enables Pythonic error handling and makes it easier
510+
to debug issues in your scripts.
511+
512+
Error handling behavior
513+
~~~~~~~~~~~~~~~~~~~~~~~
514+
515+
Errors are handled Pythonically using try-except blocks:
508516

509517
.. code:: python
510518
511519
try:
512520
mapdl.solve()
513-
except:
514-
# do something else with MAPDL
515-
pass
516-
517-
Commands that are ignored within MAPDL are flagged as errors. This is
521+
except MapdlRuntimeError as e:
522+
# Handle MAPDL runtime errors
523+
print(f"MAPDL error occurred: {e}")
524+
except Exception as e:
525+
# Handle other errors
526+
print(f"Unexpected error: {e}")
527+
528+
Commands that are ignored within MAPDL are flagged as errors by default. This is
518529
different than MAPDL's default behavior where commands that are
519-
ignored are treated as warnings. For example, in ``ansys-mapdl-core``
530+
ignored are treated as warnings. For example, in PyMAPDL
520531
running a command in the wrong session raises an error:
521532

522533
.. code:: pycon
@@ -533,14 +544,61 @@ running a command in the wrong session raises an error:
533544
534545
You can change this behavior so ignored commands can be logged as
535546
warnings and not raised as exceptions by using the
536-
:func:`Mapdl.ignore_errors() <ansys.mapdl.core.Mapdl.ignore_errors>` function. For
537-
example:
547+
:attr:`Mapdl.ignore_errors <ansys.mapdl.core.Mapdl.ignore_errors>` attribute:
538548

539549
.. code:: pycon
540550
541551
>>> mapdl.ignore_errors = True
542552
>>> mapdl.k() # warning silently ignored
543553
554+
Exception hierarchy
555+
~~~~~~~~~~~~~~~~~~~
556+
557+
PyMAPDL defines a comprehensive hierarchy of exceptions to help you handle different
558+
types of errors appropriately. All PyMAPDL exceptions inherit from :class:`MapdlException <ansys.mapdl.core.errors.MapdlException>`:
559+
560+
**Main exception classes:**
561+
562+
* :class:`MapdlRuntimeError <ansys.mapdl.core.errors.MapdlRuntimeError>` - General MAPDL runtime errors
563+
* :class:`MapdlValueError <ansys.mapdl.core.errors.MapdlValueError>` - Invalid values or parameters
564+
* :class:`MapdlFileNotFoundError <ansys.mapdl.core.errors.MapdlFileNotFoundError>` - File not found errors
565+
566+
**Specific runtime errors:**
567+
568+
* :class:`MapdlInvalidRoutineError <ansys.mapdl.core.errors.MapdlInvalidRoutineError>` - Command run in wrong routine
569+
* :class:`MapdlCommandIgnoredError <ansys.mapdl.core.errors.MapdlCommandIgnoredError>` - Commands ignored by MAPDL
570+
* :class:`MapdlExitedError <ansys.mapdl.core.errors.MapdlExitedError>` - MAPDL process has exited
571+
* :class:`MapdlConnectionError <ansys.mapdl.core.errors.MapdlConnectionError>` - Connection issues
572+
* :class:`LockFileException <ansys.mapdl.core.errors.LockFileException>` - Lock file conflicts
573+
574+
**Startup and connection errors:**
575+
576+
* :class:`MapdlDidNotStart <ansys.mapdl.core.errors.MapdlDidNotStart>` - MAPDL failed to start
577+
* :class:`PortAlreadyInUse <ansys.mapdl.core.errors.PortAlreadyInUse>` - Port conflicts
578+
* :class:`LicenseServerConnectionError <ansys.mapdl.core.errors.LicenseServerConnectionError>` - License server issues
579+
580+
Example of specific exception handling:
581+
582+
.. code:: python
583+
584+
from ansys.mapdl.core.errors import (
585+
MapdlRuntimeError,
586+
MapdlCommandIgnoredError,
587+
MapdlExitedError,
588+
)
589+
590+
try:
591+
mapdl.k(1, 0, 0, 0) # This might fail if in wrong routine
592+
except MapdlCommandIgnoredError:
593+
print("Command was ignored by MAPDL")
594+
mapdl.prep7() # Switch to correct routine
595+
mapdl.k(1, 0, 0, 0) # Retry the command
596+
except MapdlExitedError:
597+
print("MAPDL has exited unexpectedly")
598+
# Handle cleanup or restart MAPDL
599+
except MapdlRuntimeError as e:
600+
print(f"General MAPDL error: {e}")
601+
544602
545603
Prompts
546604
-------

0 commit comments

Comments
 (0)